开发者

Printing Special Escape Sequences

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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜