c# - 解析 CoDeSys .pro 文件

标签 c# parsing codesys

我正在尝试解析 .pro 文件,但我在文件中发现了奇怪的字符。

    public List<string> GetTextBlocks(int minBlockSize = 10)
    {
        if (_TextBlocks != null && _TextBlocksMinBlockSize == minBlockSize)
            return _TextBlocks;

        StreamReader pro = new StreamReader(_FileName, Encoding.ASCII);
        List<string> Blocks = new List<string>(); 

        string Content = pro.ReadToEnd();
        StringBuilder CurrentBlock = new StringBuilder();

        for (int n = 0; n < Content.Length; n++)
        {
            int c = Content[n];
            if (char.IsControl((char)c) && c != 10 && c != 13 && c != 9)
            {
                if (CurrentBlock.Length >= minBlockSize)
                    Blocks.Add(CurrentBlock.ToString());
                CurrentBlock.Clear();
            }
            else
                CurrentBlock.Append((char)c);
        }

        _TextBlocks = Blocks;
        _TextBlocksMinBlockSize = minBlockSize;

        return Blocks;//TODO: Comment
    }

以前有人尝试过吗? 谢谢!

最佳答案

你必须使用:

Encoding.UTF7

关于c# - 解析 CoDeSys .pro 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10224462/

相关文章:

Java 到 C# 的转换使用反射查找子类的公共(public)字段

c# - 为什么 InProc session 模式不需要序列化

xml - 使用 XML::Parser 解析大型 XML 文件时如何查看进度?

用Lua解析键值对

string-conversion - REAL/LREAL 到带有科学记数法结构化文本的字符串

c# - 无法通过 Entity Framework 从 WPF 数据网格更新数据库

c# - Console.WriteLine(ArrayList) 错误输出

python - 使用 sympy 求解明文线性方程组

arrays - 在 CoDeSys 中创建一个可变大小的数组

twincat - 如何在 codesys/twincat3 中传递扩展类型的数组?