2013-04-18 150 views
-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 
+3

你有没有尝试使用“\ n”..? – Pragnani

+3

或“\ r \ n”或System.getProperty(“line.separator”)? – duffymo

回答

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

试试这个:

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

不可能花1分钟时间来复制和格式化并添加一行并发布!当我还没有发布答案时,我开始了! – NINCOMPOOP

+1

@StinePike他可能没有看到答案..没有评论任何人这样,因为这个词会伤害他们..我很抱歉,如果我伤害了你的评论 – Pragnani

+0

哦,对不起,我不想伤害任何人。其实我没有资格去纠正别人。我刚看到同样的一句话。这就是为什么我不能拒绝发表这样的评论..对不起队友 – stinepike

1

您可以使用这样的事情,当你更换每“\ n”和“\ n \ n”。

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

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

1

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