本文介绍了StreamWriter:如何添加新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串写入文件.我的问题是我无法在文件中添加新行.
I want to write a string into a file. My problem is that I cannot add new lines into the file.
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(String.Format("{0}.txt", svDialog.FileName)))
{
writer.Write(String.Format("{0}\n\n{1}", this.currentRealWorldObj.Title, this.currentRealWorldObj.Description));
}
如您所见,我在String.Format方法中添加了2行("\ n \ n").但是,当我打开行时不添加.如何添加它们?
As you can see I am adding to 2 new lines ("\n\n") in the String.Format method. But when I open the lines are not added. How they can be added?
推荐答案
也许是平台问题?查看"\ n"和Environment.NewLine 试试Environment.NewLine
Maybe platform issues? Look at Difference between "\n" and Environment.NewLineTry Environment.NewLine
writer.Write(String.Format("{0}{2}{2}{1}", this.currentRealWorldObj.Title, this.currentRealWorldObj.Description,Environment.NewLine));
这篇关于StreamWriter:如何添加新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!