I have string test="first \\n middle \\n last"
string test="first \\n middle \\n last"
Now I want to replace everything "\\n"with"\n"
"\\n"
"\n"
I tried test.replaceAll("\\\\n", "\\n")and test.replaceAll("\\n", "\n")but they do not work Does anyone have a solution?
test.replaceAll("\\\\n", "\\n")
test.replaceAll("\\n", "\n")
Thank!
Use this code:
String test="first \\n middle \\n last"; System.out.println("Output: " + test.replaceAll("\\\\n", "\n"));
Output: first middle last
"\\\\"+ "n"for backslash "\\"and "n"in the source line is replaced by"\n"
"\\\\"
"n"
"\\"