解析CoDeSys .pro文件

时间:2012-04-19 08:37:59

标签: 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
    }

以前有人试过吗? 谢谢!

1 个答案:

答案 0 :(得分:2)

你必须使用:

Encoding.UTF7