C# 讀取 CMD結果 換行 拆解 [C# Split text with ‘\r\n’ / C# ReadToEnd \r\n]

C# 讀取 CMD結果 換行 拆解 [C# Split text with ‘\r\n’ / C# ReadToEnd \r\n]

C# 讀取 CMD結果 換行 拆解 [C# Split text with ‘\r\n’ / C# ReadToEnd \r\n]



資料來源: https://stackoverflow.com/questions/22185009/split-text-with-r-n


Code:

var text = 
  "somet interesting text\n" +
  "some text that should be in the same line\r\n" +
  "some text should be in another line";


string[] lines = text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
Console.WriteLine("Nr. Of items in list: " + lines.Length); // 2 lines
foreach (string s in lines)
{
   Console.WriteLine(s); //But will print 3 lines in total.
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *