Home arrow static arrow Java Programming [Archive] - string replace question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - string replace question
This topic has 5 replies on 1 page.

Posts:111
Registered: 1/14/04
string replace question  
Aug 8, 2004 11:02 PM



 
how do i replace " ' " with " \' "?

I tried using string.replaceAll(" ' ", " \' ") but its not working.

Help pls.
 

Posts:964
Registered: 7/23/03
Re: string replace question  
Aug 8, 2004 11:07 PM (reply 1 of 5)



 
try
string.replaceAll(" ' ", " \\' ") 
 

Posts:8,813
Registered: 10/4/00
Re: string replace question  
Aug 8, 2004 11:08 PM (reply 2 of 5)



 
string.replaceAll("'", "\\\\'")

You need to escape the backslashes to put them in a string so \\\\ becomes
and them the regular expression parser needs
because it uses backslash as an escape character..
 

Posts:8,813
Registered: 10/4/00
Re: string replace question  
Aug 8, 2004 11:10 PM (reply 3 of 5)



 
I missed the spaces
string.replaceAll(" ' ", " \\\\' ")
 

Posts:964
Registered: 7/23/03
Re: string replace question  
Aug 8, 2004 11:15 PM (reply 4 of 5)



 
try
string.replaceAll(" ' ", " \\' ")

Opp.... wrong here... :P
 

Posts:111
Registered: 1/14/04
Re: string replace question  
Aug 8, 2004 11:21 PM (reply 5 of 5)



 
Thanks to all of you!

string.replaceAll(" ' ", " \ \ \ \ ' ") does work!
 
This topic has 5 replies on 1 page.