I have a project in the works to read and convert CSV files based on a set of arbitrary rules, pick a file tell the program how it should output the data based on the input and parse the file.
The problem that I have is when I read the lines from my input files it will sometimes read additional lines or split lines halfway through into two lines, I initially used ReadAllLines then tested with this code:
int testCount = 0;
StreamReader sr = File.OpenText(_FilePath.Text);
while(!sr.EndOfStream)
{
sr.ReadLine();
testCount++;
}
sr.Close();
sr.Dispose();
Console.WriteLine("Lines in For: " + testCount);
and found that a file that has 627 lines is being read as having 681 lines (using both ReadAllLines and counting the lines in the above code.
I tried looking for people having the same issue and tried looking to see if there was perhaps a max length of a 'line' in these methods, Nothing turned up on google, the first line in the file that acts up is this one (changed information in the line to protect privacy, all special characters are present)
CODE, A/B Company Name, CONTACT NAME, ATTN NAME A/B, 1234 CORPORATE CORP ST, Smithington, SM, 1234, , 123-456-7890, 123-456-7890, 12345 Plum ROAD, , Nowhere, NW, 12345, A/B Company Name2, Courier, , "Some A Info B For.Shipping Accnt. # 123456789 calendar days early^ 3 days late.", ,
The file itself was exported out of an excel Spreadsheet to CSV, all commas in the original file were replaced with ^ (to prevent issues) and will be re-converted to commas later.
So, anyone know of a limit to the length of a line in ReadAllLines or is there something else going on here behind the scenes? since this was exported from Excel (originally a DBF file) I don't 'think' this is an issue with the file, but I could be wrong, anything I can do to find out?