C#: New line and tab characters in strings

前端 未结 6 1469
名媛妹妹
名媛妹妹 2021-01-17 07:40
StringBuilder sb = new StringBuilder();
sb.Append(\"Line 1\");
//insert new line character
//insert tab character
sb.Append(\"Line 2\");
using (StreamWriter sw = new         


        
6条回答
  •  不思量自难忘°
    2021-01-17 08:16

    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).

提交回复
热议问题