I have a method that reads a file. This file has roughly 30000 lines. However when I read it into an array I get a random length for my array. I have seen it as low 6000.
I used both
string[] lines = System.IO.File.ReadAllLines(@"C:\out\qqqqq.txt");
and
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\out\qqqqq.txt");
(and use a counter.)
But I get the same result. I can see in Excel these are too small.
If the line endings in the file are inconsistent (sometimes
\n, sometimes\r\nand sometimes\r) then you could try reading the entire file as a string and splitting it yourself:For large files, this is inefficient, because it needs to read the entire file – using
StreamReaderyou would be able to read the file line-by-line as you’re processing it. If performance is an issue, then you could write simple tool that first corrects the line endings.