to a String. That is, I want the string to be backslash + double quote. \" just gives the double quote, \\" becomes an unterminated string, and \\\" is back to the double quote without the backslash. I'm pretty sure that unicode would have the same result. The must be some way to do this, right?
Hmm, that does work. Actually what I am really trying to do is replace all occurances of double quotes in a String with the escaped double quote. So more along the lines of
String test = "\"abc"; System.out.println(test.replaceAll("\"", "\\\""));
this just prints out "abc I'm guessing that this is a regular expression problem then?
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: