如何使java中的\ n显示为普通文本?

时间:2017-08-09 13:35:25

标签: java string

正如标题所说,如何使java中的\n显示为普通文本?

例如:

String example = "In Java, we use \n to make a new line.";
System.out.println(example);

输出结果为:

In Java, we use to make a new line.

如何使输出看起来像这样:

In Java, we use \n to make a new line.

4 个答案:

答案 0 :(得分:3)

尝试使用双反斜杠\\n,如下所示:

String example = "In Java, we use \\n to make a new line.";

答案 1 :(得分:3)

您必须使用转义字符Select top(1) with ties * from yourtable order by row_number() over (partition by TaskName order by startDt)

\

有关详细说明和更多示例,请参阅Java文档§ Escape Sequences一章。

答案 2 :(得分:2)

使用\

逃离\\个字符
String example = "In Java, we use \\n to make a new line.";

答案 3 :(得分:-1)

尝试使用此String example = "In Java, we use \\n to make a new line."; 代替此\\n