• <bdo id='cYpil'></bdo><ul id='cYpil'></ul>

    1. <small id='cYpil'></small><noframes id='cYpil'>

    2. <i id='cYpil'><tr id='cYpil'><dt id='cYpil'><q id='cYpil'><span id='cYpil'><b id='cYpil'><form id='cYpil'><ins id='cYpil'></ins><ul id='cYpil'></ul><sub id='cYpil'></sub></form><legend id='cYpil'></legend><bdo id='cYpil'><pre id='cYpil'><center id='cYpil'></center></pre></bdo></b><th id='cYpil'></th></span></q></dt></tr></i><div id='cYpil'><tfoot id='cYpil'></tfoot><dl id='cYpil'><fieldset id='cYpil'></fieldset></dl></div>
        <legend id='cYpil'><style id='cYpil'><dir id='cYpil'><q id='cYpil'></q></dir></style></legend>
        <tfoot id='cYpil'></tfoot>

        将文本转储到带有换行符的文件

        Dump text to file with line breaks(将文本转储到带有换行符的文件)

          <small id='kFb9C'></small><noframes id='kFb9C'>

            • <legend id='kFb9C'><style id='kFb9C'><dir id='kFb9C'><q id='kFb9C'></q></dir></style></legend>
                <i id='kFb9C'><tr id='kFb9C'><dt id='kFb9C'><q id='kFb9C'><span id='kFb9C'><b id='kFb9C'><form id='kFb9C'><ins id='kFb9C'></ins><ul id='kFb9C'></ul><sub id='kFb9C'></sub></form><legend id='kFb9C'></legend><bdo id='kFb9C'><pre id='kFb9C'><center id='kFb9C'></center></pre></bdo></b><th id='kFb9C'></th></span></q></dt></tr></i><div id='kFb9C'><tfoot id='kFb9C'></tfoot><dl id='kFb9C'><fieldset id='kFb9C'></fieldset></dl></div>
                  <tbody id='kFb9C'></tbody>
                <tfoot id='kFb9C'></tfoot>

                  <bdo id='kFb9C'></bdo><ul id='kFb9C'></ul>
                  本文介绍了将文本转储到带有换行符的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  private void btnDump_Click(object sender, EventArgs e)
                  {
                      using (StreamWriter sw = new StreamWriter("E:\TestFile.txt"))
                      {
                          // Add some text to the file.
                          sw.WriteLine(txtChange.Text);
                      }
                  }
                  

                  这会将 txtChange 的文本转储到文本文件中.txtChange 是一个富文本框,其中包含换行符(新行).

                  This dumps the text of txtChange to a text file. txtChange is a Rich text box and has line breaks (new lines) in it.

                  当用户单击转储按钮时,所有文本都被转储但不在新行上.

                  When the user clicks the Dump button all the text is Dumped but not on new lines.

                  例如txt更改看起来像

                  E.g. txtChange looks like

                  1
                  2
                  3
                  4
                  

                  转储文本看起来像 1234

                  如何格式化文本的转储以使文本换行?

                  推荐答案

                  您应该使用 Lines 属性改为:

                  You should use the Lines property instead:

                  File.WriteAllLines(@"E:TestFile.txt", txtChange.Lines);
                  

                  您实际上不需要使用流,因为 File 类包含这些静态便捷方法 - 简明扼要.

                  You don't really need to use a stream since the File class contains these static convenience methods - short and to the point.

                  Above 将使用文本框 txtChange 中包含的文本行替换任何现有内容.如果您想追加 内容,请改用适当命名的 File.AppendAllLines().

                  Above will replace any existing content with the text lines contained in your text box txtChange. If you want to append content use the appropriately named File.AppendAllLines() instead.

                  这篇关于将文本转储到带有换行符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                    <bdo id='kxbwz'></bdo><ul id='kxbwz'></ul>

                    • <small id='kxbwz'></small><noframes id='kxbwz'>

                    • <i id='kxbwz'><tr id='kxbwz'><dt id='kxbwz'><q id='kxbwz'><span id='kxbwz'><b id='kxbwz'><form id='kxbwz'><ins id='kxbwz'></ins><ul id='kxbwz'></ul><sub id='kxbwz'></sub></form><legend id='kxbwz'></legend><bdo id='kxbwz'><pre id='kxbwz'><center id='kxbwz'></center></pre></bdo></b><th id='kxbwz'></th></span></q></dt></tr></i><div id='kxbwz'><tfoot id='kxbwz'></tfoot><dl id='kxbwz'><fieldset id='kxbwz'></fieldset></dl></div>
                      <tfoot id='kxbwz'></tfoot>

                            <tbody id='kxbwz'></tbody>
                          • <legend id='kxbwz'><style id='kxbwz'><dir id='kxbwz'><q id='kxbwz'></q></dir></style></legend>