如何在字符串中添加空行?这样一个字符串看起来像这样:
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
"This is an example of something\n\nThis is still an example of something"
尝试这个 :
"This is an example of something\n\nThis is still an example of something"
如果您要在 UI 中用作格式化和显示,只需将“\n”添加到您的字符串或 br 标记。
您可以使用类似的东西,将每个“\n”替换为“\n\n”。
str = str.replaceAll("\n", "\n\n");
str 是您从 editText 获得的字符串。