views:

74

answers:

3

i have a streamreader which loads up a csvfile, the issue is that there is one extra row at the top of the data that i want to ignore.

I am using the CSVReader project which is great but

 csv.GetFieldHeaders(); 

always looks at the first row. Instead of going into the CSVReader source code and changing it, i thought it might be easier if i can "strip" out this first row from the streamreader itself before injecting it into the csvReader. Is this possible?

+2  A: 

StreamReader is a virtual class, so you could create an inherited class that delegates all important functionality to some underlying StreamReader, with the exception that it skips the first line of text (or you could inherit from the TextReader type). If the CSVReader takes the StreamReader or TextReader as an argument, this should work fine.

Tomas Petricek
+3  A: 

The simplest way would just be to call ReadLine() yourself before you pass the reader on to the CSVReader.

Jon Skeet
+8  A: 

Just read a line from the SR before you pass it to the CSVReader constructor. For example:

using (var sr = new StreamReader("data.csv")) {
    sr.ReadLine();
    using (var csv = new CsvReader(sr, true)) {
        // etc..
    }
}
Hans Passant