can anyone advise why i encountered index out of bouns exception when running this method to replace the value by $
sign?
E.g. i pass in a message $$vmdomodm$$
message = message.replaceAll("$", "$");
I tried to look at this forum thread but couldnt understand the content
http://www.coderanch.com/t/383666/java/java/String-replaceAll
It is special character you need to use escape character
Try with this \\$
and it doesn't make sense in your code you are trying to replacing the content with same
String message = "$$hello world $$";
message = message.replaceAll("\\$", "_");
System.out.println(message);
output
__hello world __
Update
String message = "$hello world $$";
message = message.replaceAll("$", "\\$");
System.out.println(message);
output
$hello world $$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With