如何在StringBuilder中附加换行符 [英] How to append a newline to StringBuilder
本文介绍了如何在StringBuilder中附加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 StringBuilder
object,
I have a StringBuilder
object,
StringBuilder result = new StringBuilder();
result.append(someChar);
现在我想在 StringBuilder $ c中追加换行符$ C>。我该怎么办?
Now I want to append a newline character to the StringBuilder
. How can I do it?
result.append("/n");
不起作用。所以,我正在考虑使用Unicode编写换行符。这会有帮助吗?如果是这样,我该如何添加?
Does not work. So, I was thinking about writing a newline using Unicode. Will this help? If so, how can I add one?
推荐答案
它应该是
r.append("\n");
但我建议你这样做,
r.append(System.getProperty("line.separator"));
System.getProperty(line.separator)
在java中为您提供依赖于系统的换行符。同样来自Java 7的方法直接返回值: System.lineSeparator()
System.getProperty("line.separator")
gives you system-dependent newline in java. Also from Java 7 there's a method that returns the value directly: System.lineSeparator()
这篇关于如何在StringBuilder中附加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文