Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to do that replacement, the problem is, in replace() I have to put a \ before ", so does to really do a replacement.

str = str.replace("\"", "\"");


this is not possible:

str = str.replace("\"", "\\"");


How can I solve this?
Posted

If I understand, you want to replace " with \". To do this the line is:

str = str.replace("\"", "\\\"");


Each character is escaped.
 
Share this answer
 
Comments
Maxdd 7 15-Jul-11 11:45am    
So obvious, thank you very much.
Java
str = str.Replace("\"", "\\\"");
 
Share this answer
 
Comments
Maxdd 7 15-Jul-11 11:45am    
Thanks for helping.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900