C# TextWriter 每 1024 个字符插入换行符 [英] C# TextWriter inserting line break every 1024 characters

查看:36
本文介绍了C# TextWriter 每 1024 个字符插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 textwriter 将数据写入文本文件,但如果该行超过 1024 个字符,则会插入换行符,这对我来说是个问题.关于如何解决此问题或增加字符限制的任何建议?

I'm using the textwriter to write data to a text file but if the line exceeds 1024 characters a line break is inserted and this is a problem for me. Any suggestions on how to work round this or increase the character limit?

textWriter.WriteLine(strOutput);

非常感谢

推荐答案

我编写了一个示例应用程序,用于写入和读取 1025 个字符的字符串.尺寸永远不会改变.虽然如果我用 notepad.exe (Windows) 打开它,我可以在第二行看到额外的字符.这些似乎是记事本的限制.这是我的示例代码

I wrote a sample app that writes and read a 1025 character string. The size never changes. Although if I opened it with notepad.exe (Windows) I can see the extra character in the second line. These seems like a notepad limitation. Here is my sample code

    static void Main(string[] args)
    {
        using (TextWriter streamWriter = new StreamWriter("lineLimit.txt")) {
            String s=String.Empty;
            for(int i=0;i<1025;i++){
                s+= i.ToString().Substring(0,1);
            }
            streamWriter.Write(s);
            streamWriter.Close();
        }
        using (TextReader streamReader = new StreamReader("lineLimit.txt"))
        {
            String s = streamReader.ReadToEnd();
            streamReader.Close();
            Console.Out.Write(s.Length);
        }
    }

这篇关于C# TextWriter 每 1024 个字符插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆