How to replace dollar signs with ""?
I have a program that prompts the user for an entry and they could potentially enter in a lot of things, but I want to catch the dollar signs and convert them to "" in terms of strings. I've tried using the replace method on my string like:
But that obviously doesn't work. What can I do to achieve this? What if there are multiple dollar signs? Is there a method on String which I can call to replace all dollar signs?
Re: How to replace dollar signs with ""?
Try
Code :
String.replaceAll(String statement, String replacement)
String (Java 2 Platform SE v1.4.2)
Re: How to replace dollar signs with ""?
Quote:
Originally Posted by
Tsarin
I tried that...It still didn't work :\
The string value doesn't become changed at all
Re: How to replace dollar signs with ""?
If you read the API for String you would notice that the replace methods return a new String with the replacement carried out.
So all you need to do is assign the replaced version back to input.