$ in replacement text of string.
If you want to replace a part of the string with other string which consists a character $ in it, with normal replace/replaceAll will give error. To resolve it see following code.
String str = "asdf$fgh";
String str2 = "hghf-j-kjfi";
//Matcher m
str = str.replaceAll("\\$", "\\\\\\$");
str = str2.replaceAll("-j-", str);
System.out.println(str);


0 Comments:
Post a Comment
<< Home