I want to escape escape sequences in a string.
Example: if I had a string whose contents were "\n\u0073", I need to escape them in such a way that if I printed it to the command line, I would see
this:
\n\u0073
instead of:
s
I'll also be escaping double quotes (") and backslashes (\), and I figured out an expression to escape those already:
Pattern p = Pattern.compile("([\"\\\\])");
String str = p.matcher("\"\n\u0073\\"").replaceAll("\\\\$1");
This yields me:
\"
s\\
It doesn't take care of the escape sequences, though. What I want is:
\"\n\u0073\\
What modifications do I need to make to escape the escape sequences?
"\n\u0073"in your code, it's too late, because at runtime there is no escape sequence. At runtime, that string is a newline character followed by a lowercases."\n"when it sees a'\u0010'character.