I am trying to replace all the $ characters in string expression
An example string is $ $ S with S and the other with the end and here's the end.
so that the $ letters are surrounded by spaces
I've tried When I try to escape $ character like this: When I try the following: Finally when I try this: It does not have any effect on string. I know it's stupid that I am not getting anybody here anybody can help? You will need two slashes on both sides The first one is avoided by a second slash which will be passed on to regular expressions, then the expression "$$" matches the $ sign. And you want to change it with that. You must also avoid the second parameter because all though this is not a regular expression \ $ $ and the $ sign according to the document is a special case: Note that The result of the backslash () and the dollar sign ($) in the replacement string can be different if it is considered to be a literal replacement string; View Matcher.replaceAll Use Matcher.quoteReplacement (java.lang.String) to suppress these special words. string.replaceAll ("$", "$"); This is the result of an invalid argument exception.
string.replaceAll ("\ $", "$"); Before I even build, I get an invalid escape sequence error.
string.replaceAll ("\\\\ $" , "$");
string.replaceAll ("\\ $", "\\ $");
Comments
Post a Comment