Originally posted by Yuriy Zilbergleyt:
I'm guessing that this is a regular expression problem then?
Yes. It's tricky because the backslash is meaningful to both
Java and the regexp parser. To do this, first write the actual expression you want to replace with:
\\"
Then escape each of the special characters so they'll pass through the Java parser untouched:
\\\\\"
So you need to say
System.out.println(test.replaceAll("\"", "\\\\\""));
Five slashes!