Using Split here:
reader .ReadToEnd() .Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
not equivalent to ReadLine . If you look at the ReadLine source, StreamReader.cs , you will see that it handles the line terminators: \ r, \ n and \ r \ n correctly. ReadLine does not return an extra empty line when the line terminator is \ r \ n, which is typical for DOS / Windows. Split "sees" (parses) \ r, followed by \ n as two separate delimiters, and returns an empty string.
'StringSplitOptions.RemoveEmptyEntries' in the above code removes these empty lines, but also removes any empty lines that also appear in the input.
Thus, to enter line1 \ r \ p line3 \ r ReadLine returns 3 lines. The second is empty. Split creates 4 lines. (After the last \ r. There is an additional line). Then he removes the 2nd and 4th.
Please note that Split not suitable for parsing text strings that are "post-service". That is, the separator appears after the token. So far, Split is suitable for infix, where separators appear between tokens. This is the difference between a, b, c and line1 \ r, line2, line3 \ r. For these inputs, Split returns 3 lines or 4 lines, respectively.
Andrew Dennison May 22 '14 at 3:35 a.m. 2014-05-22 03:35
source share