开发者

Writing into a text file line by line

开发者 https://www.devze.com 2023-01-27 08:38 出处:网络
I am writing a text into a file. I am getting a column from database and stored it in a string and writing it in a text file. That column contains c# code and it is writing like a single line with sma

I am writing a text into a file. I am getting a column from database and stored it in a string and writing it in a text file. That column contains c# code and it is writing like a single line with small squares for next line(space). I need to write it line by line. Here is my code.

using (var dest = File.AppendText(Pa开发者_StackOverflow中文版th.Combine(_logFolderPath, "a.txt")))
{
    dest.WriteLine(line.TrimStart());
}  

Any suggestion?


Does Notepad show small squares for new lines, but when you look at the file in Visual Studio it's OK? If so, my guess is that this will fix it:

dest.WriteLine(line.TrimStart().Replace("\n", Environment.NewLine));


try this

File.AppendAllText(Path.Combine(_logFolderPath, "a.txt", 
    line.Trim() + Environment.NewLine));


dest.WriteLine(line.TrimStart().Replace("\n", Environment.NewLine).Replace("\r", Environment.NewLine));
0

精彩评论

暂无评论...
验证码 换一张
取 消