1

如何在字符串中添加空行?这样一个字符串看起来像这样:

This is an example of something
This is still an example of something

变成这样:

This is an example of something

This is still an example of something
4

4 回答 4

6
"This is an example of something\n\nThis is still an example of something"
于 2013-04-18T18:33:25.300 回答
2

尝试这个 :

"This is an example of something\n\nThis is still an example of something"
于 2013-04-18T18:34:17.040 回答
2

如果您要在 UI 中用作格式化和显示,只需将“\n”添加到您的字符串或 br 标记。

于 2013-04-18T18:38:22.237 回答
1

您可以使用类似的东西,将每个“\n”替换为“\n\n”。

str = str.replaceAll("\n", "\n\n");

str 是您从 editText 获得的字符串。

于 2013-04-18T18:38:07.233 回答