我在处理正在处理的控制台应用程序的输出数据中的换行符时遇到问题。下面的简化示例将outDataString写入out.txt,而没有换行符。在这种情况下,如何对out.txt中的换行有任何想法?

FileStream ostrm;
StreamWriter writer;

string outDataString = "Hi, this is the out data.\nWith a few\n line breaks.";

ostrm = new FileStream("out.txt", FileMode.OpenOrCreate, FileAccess.Write);
writer = new StreamWriter(outDataString);

Console.SetOut(writer);
Console.write(outDataString);


谢谢。

最佳答案

string outDataString = string.Format(
"Hi, this is the out data.{0}With a few{0} line breaks.",
Environment.NewLine);

10-07 20:11