【问题标题】:Is StreamReader changing my line endings?StreamReader 是否改变了我的行尾?
【发布时间】:2013-02-08 05:32:22
【问题描述】:

我注意到 GitHub for windows 报告了一些我认为不应该更改的文件。 问题出现在我们的应用程序中读取的一些 .txt 文件中。运行程序后,报告所有读取的 .txt 文件的每一行结尾都加倍: 例如:

Line1
Line2

变成

Line1

Line2

我有一种感觉,这是由于某些行尾问题,可能是 git 中的错误设置,所以我查看了 Notepad++ 显示所有字符。在运行程序之前,文件如下所示:

Line1   CRLF
Line2   CRLF
Line3

然后,他们变成:

Line1   CR
CRLF
Line2   CR
CRLF
Line3

因此,GH4W 报告它们已更改似乎是正确的。问题是,他们不应该这样。 我正在使用这样的 StreamReader 阅读它们:

// ASCII.RodBarcodes holds path to RodBarcodes.txt
using (StreamReader sr = new StreamReader(ASCII.RodBarcodes))
        {
            int count = 0;
            string line = sr.ReadLine();
            while (line != null)
            {
                Rods.Add(new AnemometerRod());
                Rods[count].Barcode = line;
                line = sr.ReadLine();
                count++;
            }
        }

这些额外的 CR 来自哪里?

【问题讨论】:

    标签: git streamreader line-endings


    【解决方案1】:

    既然这个问题很快得到了赞成,我想我最好自己回答一下。

    这个问题与StreamReader 无关(当然)。实际上发生的事情是,程序自动更新了来自网络共享的文件(我从别人那里接管了一个项目),其中行尾一团糟。从源头修复此问题即可解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 2019-12-21
      • 2012-10-21
      • 1970-01-01
      相关资源
      最近更新 更多