I have a string (pulled from the web) wh开发者_运维百科ich may look like this: \something\to\do. When I print this string via System.out.println \s \t and \d are treated as escape sequences. How can I print the sting in such a way so that escape sequences are ignored?
If you want to have the following output:
\something\to\do
Then you need to double backslash the backslash characters to make them into backslash literals:
string myString = "\\something\\to\\do";
You have to escape the backslashes:
String s = "\something\to\do";
System.out.println(s.replaceAll("\\", "\\\\")); // prints "\something\to\do"
精彩评论