如何使用字符串变量打印白色 space 字符?
how to print white space character using string variable?
如果String s="\t\n";
然后我想打印 s
结果将是:"\t\n"
.
示例:
String s = "\t\n";
System.out.println(s);
Output: \t\n
有什么办法吗?
只需使用str.replace()
:
String s = "\n\t";
s = s.replace("\n", "\n");
s = s.replace("\t", "\t");
System.out.println(s);
Output: \n\t
你可以用"\n\t"
做so.Since \n
是换行符,\t
是制表符。但是如果你需要打印 \
你需要使用 \
如果String s="\t\n";
然后我想打印 s
结果将是:"\t\n"
.
示例:
String s = "\t\n";
System.out.println(s);
Output: \t\n
有什么办法吗?
只需使用str.replace()
:
String s = "\n\t";
s = s.replace("\n", "\n");
s = s.replace("\t", "\t");
System.out.println(s);
Output: \n\t
你可以用"\n\t"
做so.Since \n
是换行符,\t
是制表符。但是如果你需要打印 \
你需要使用 \