更改 FileHelpers EOL 字符

发布于 2024-12-26 16:13:31 字数 156 浏览 5 评论 0原文

我正在尝试将 10GB 的 .dat 文件解析为 .NET 中可识别的内容。列分隔符是“~”,EOL 是“++EOL++”。我知道如何处理分隔符,但当文件中没有实际换行符时,我找不到处理“++EOL++”的简单方法。这可以通过 FileHelpers 中的选项来处理还是我必须编写一些自定义的东西?

I'm trying to parse 10GB of .dat files into something recognizable in .NET. The column delimiter is a '~' and the EOL is a '++EOL++'. I know how to handle the delimiter but I can't find an easy way to handle the '++EOL++' when there are no actual line breaks in the file. Can this be handled with an option in FileHelpers or would I have to write something custom?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2025-01-02 16:13:31

默认情况下,No FileHelpers 不支持具有异常行尾字符序列的文件。

预解析文件并替换 EOL 序列可能是最简单的方法。但是,它是一个可扩展的库,因此您可以创建自己的 DataStorage 子类。您本质上必须重写

public override object[] ExtractRecords()
{
    using (MyStreamReader reader = new MyStreamReader(fileName, base.mEncoding, true, 102400))
    {
        T[] localArray = this.ReadStream(reader, maxRecords);
        reader.Close();
        return localArray;
    }
}

并创建一个新类 MyStreamReader,它与(不幸的是 sealedInternalStreamReader 相同,但 ReadLine 除外。包含 EOL 代码

switch (ch)
{
    case '\n':
    case '\r':

    etc...
}

(顺便说一下,我指的是 FileHelpers 2.9.9 的源代码。版本 2.0.0 似乎使用 System.IO.StreamReader 所以你可以只需对其进行子类化,而不是复制 InternalStreamReader

No FileHelpers does not support files with unusual end-of-lines character sequences by default.

It would probably be easiest to pre-parse the file and replace the EOL sequences. However, it is an extensible library, so you could create your own DataStorage subclass. You would essentially have to override

public override object[] ExtractRecords()
{
    using (MyStreamReader reader = new MyStreamReader(fileName, base.mEncoding, true, 102400))
    {
        T[] localArray = this.ReadStream(reader, maxRecords);
        reader.Close();
        return localArray;
    }
}

and then create a new class MyStreamReader, which would be identical to the (unfortunately sealed) InternalStreamReader except for ReadLine which contains the EOL code

switch (ch)
{
    case '\n':
    case '\r':

    etc...
}

(By the way I'm referring to the source code for FileHelpers 2.9.9. Version 2.0.0 seems to use a System.IO.StreamReader so you can just subclass it instead of duplicating InternalStreamReader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文