NavigationUser loginscreen-scraper.com welcomes...
Currently online
There are currently 0 users and 2 guests online.
Recent comments
|
string.replaceAll()I am having problems eliminating "$" from my record set. I tried; string.replaceAll("$","") but it did nothing. also string.replace('$','') which threw an error. Can you tell me the best way to clean my data using replace?
|
SearchNew Video!Tags Throughout this Site |
replaceAll() is a regex function
this is because string.replaceAll() actually works with regular expression patterns. The source of your trouble is that "$" is a reserved character in regex, which matches at the beginning of a line. The "pattern" of "$" is matching the line's start position, but doesn't actually match any text. Consequently, replacing nothing with a blank string does nothing :)
What you'll have to do is escape the "$":
// in Java, of course...
string.replaceAll("\\$", "");
The double escape character is necessary for the backslash to wiggle its way into the regular expression, past Java's own character escaping backslash.
Let me know if that fixes it for you!