如何在Java中的字符串中添加换行符? [英] How can I add a newline character to a String in Java?
本文介绍了如何在Java中的字符串中添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java应用程序中,我正在创建一个如下所示的字符串(通过串联):
In a Java application, I am creating a String like below (by concatenation):
String notaCorrente = dataOdierna + " - " + testoNotaCorrente;
我的问题是我想在此String的末尾添加一个类似HTML换行符的字符(该字符将显示在HTML页面中).
My problem is that I want to add also something like an HTML newline character at the end of this String (that will be shown into an HTML page).
我该如何实施?
推荐答案
Java中的换行符为"\ n",如下所示:
The newline character in Java is "\n" which will look like this:
String notaCorrente = dataOdierna + " - " + testoNotaCorrente + "\n";
但是,它不会在HTML页面上按预期显示.您可以尝试添加html中断标签,或添加
(换行)和
(回车)HTML实体:>
However, this will not display as you expect on your HTML page. You can try adding an html break tag, or add the
(Line Feed) and
(Carriage Return) HTML entities:
String notaCorrente = dataOdierna + " - " + testoNotaCorrente + "<br>";
或
String notaCorrente = dataOdierna + " - " + testoNotaCorrente + " 
";
这篇关于如何在Java中的字符串中添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文