How do you append new line(\n\r) character in StringBuilder
?
views:
521answers:
3
+10
A:
I would make use of Environment.NewLine Property
Something like
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Foo{0}Bar", Environment.NewLine);
string s = sb.ToString();
Or
StringBuilder sb = new StringBuilder();
sb.Append("Foo");
sb.Append("Foo2");
sb.Append(Environment.NewLine);
sb.Append("Bar");
string s = sb.ToString();
EDIT:
If you wish to have a new line after each append, you can have a look at @Ben Voigt answer.
astander
2010-04-11 16:36:08
It's possible to mix Append and AppendLine to get new lines where you want them, not after every Append. Also, I linked to the zero-argument version of AppendLine which appends nothing but the newline sequence.
Ben Voigt
2010-04-11 17:04:02