Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: New line and tab characters in strings

Tags:

c#

StringBuilder sb = new StringBuilder(); sb.Append("Line 1"); //insert new line character //insert tab character sb.Append("Line 2"); using (StreamWriter sw = new StreamWriter("example.txt")) {     sq.Write(sb.ToString()); } 

How can insert a new line and tab character in this example?

like image 599
burnt1ce Avatar asked Jan 28 '10 19:01

burnt1ce


1 Answers

StringBuilder sb = new StringBuilder(); sb.Append("Line 1"); sb.Append(System.Environment.NewLine); //Change line sb.Append("\t"); //Add tabulation sb.Append("Line 2"); using (StreamWriter sw = new StreamWriter("example.txt")) {     sw.Write(sb.ToString()); } 

You can find detailed documentation on TAB (and other escape character here).

like image 191
Patrick Desjardins Avatar answered Sep 17 '22 19:09

Patrick Desjardins