C#: New line and tab characters in strings

前端 未结 6 1427
名媛妹妹
名媛妹妹 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:05

    It depends on if you mean '\n' (linefeed) or '\r\n' (carriage return + linefeed). The former is not the Windows default and will not show properly in some text editors (like Notepad).

    You can do

    sb.Append(Environment.NewLine);
    sb.Append("\t");
    

    or

    sb.Append("\r\n\t");
    

提交回复
热议问题