将空行添加到字符串

时间:2013-04-18 18:32:17

标签: java android string

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

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 个答案:

答案 0 :(得分:6)

"This is an example of something\n\nThis is still an example of something"

答案 1 :(得分:2)

试试这个:

"This is an example of something\n\nThis is still an example of something"

答案 2 :(得分:1)

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

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

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

答案 3 :(得分:1)

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