gpt4 book ai didi

c# - StreamWriter : How to add a new line?

转载 作者:行者123 更新时间:2023-12-05 08:19:00 25 4
gpt4 key购买 nike

我想将一个字符串写入一个文件。我的问题是我无法在文件中添加新行。

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")。但是当我打开时没有添加这些行。如何添加它们?

最佳答案

有一个特定的WriteLine功能。

例如:

writer.WriteLine(this.currentRealWorldObj.Title);
writer.WriteLine();
writer.WriteLine();
writer.WriteLine(this.currentRealWorldObj.Description);

关于c# - StreamWriter : How to add a new line?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com