How to skip first line while reading csv using streamreader

Just read it first before you get into the loop. I’d do this:

using (StreamReader sr = new StreamReader(filePath))
{
    string headerLine = sr.ReadLine();
    string line;
    while ((line = sr.ReadLine()) != null)
    {
         ...
    }
}

(I don’t like using Peek, personally.)

Then when you write out the output, start with headerLine.

Leave a Comment

tech