StreamReader.ReadLine not working over TCP when using \r as line terminator

前端 未结 1 1954
谎友^
谎友^ 2021-01-21 01:48

When I use only \\r as a line terminator, the StreamReader.ReadLine() method doesn\'t work. It works if I use Environment.NewLine, \

相关标签:
1条回答
  • 2021-01-21 02:27

    I solved the problem with my own ReadLine method

    public static class StreamReaderExtensions
    {
        public static string ReadLineSingleBreak(this StreamReader self)
        {
            StringBuilder currentLine = new StringBuilder();
            int i;
            char c;
            while ((i = self.Read()) >= 0)
            {
                c = (char)i;
                if (c == '\r'
                    || c == '\n')
                {
                    break;
                }
    
                currentLine.Append(c);
            }
    
            return currentLine.ToString();
        }
    }
    
    0 讨论(0)
提交回复
热议问题