Home arrow static arrow Java Programming [Archive] - replaceAll(String, String) method of String
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - replaceAll(String, String) method of String
This topic has 2 replies on 1 page.

Posts:22
Registered: 12/19/03
replaceAll(String, String) method of String   
Jul 20, 2004 5:19 AM



 
Hi folks,

I am facing a problem with replaceAll() method in String class.

if I try to do the following it is giving me problem.

String str = "Hello $ How R U";
str = str.replaceAll("$","$$");

Can some help me out in solving this.

Thanks
Madan
 

Posts:24,036
Registered: 2/3/03
Re: replaceAll(String, String) method of String   
Jul 20, 2004 5:22 AM (reply 1 of 2)



 
String str = "Hello $ How R U";str = str.replaceAll("\\$","\\$\\$");System.out.println(str);  // Hello $$ How R U
 

Posts:24,036
Registered: 2/3/03
Re: replaceAll(String, String) method of String   
Jul 20, 2004 5:22 AM (reply 2 of 2)



 
The '$' sign is a special character in regular expressions, and therefore needs to be escaped.

HTH,
§
 
This topic has 2 replies on 1 page.