0

愚蠢的新手问题。我可以使用生成电子邮件正文,

email.setMsg("Paragraph 1 goes here."); 

输出:

Paragraph 1 goes here.

现在我想要生成的看起来像:

Paragraph 1 goes here.
Paragraph 2 goes here.

但如果我使用:

email.setMsg("Paragraph 1 goes here."); 
email.setMsg("Paragraph 2 goes here."); 

我得到的是:

Paragraph 2 goes here.

如何添加手动换行符?

4

1 回答 1

2

假设您在 UNIX 系统上:

email.setMsg("Paragraph 1 goes here.\nParagraph 2 goes here."); 

要使代码平台不可知,您可以使用以下命令查找换行符System.getProperty("line.separator")

String ENDL = System.getProperty("line.separator");
email.setMsg("Paragraph 1 goes here." + ENDL + "Paragraph 2 goes here."); 

如果您使用 HTML 电子邮件:

email.setMsg("<p>Paragraph 1 goes here.</p><p>Paragraph 2 goes here.</p>"); 
于 2013-06-27T02:28:24.060 回答