Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to remove the first line from a StreamReader

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?

like image 840
leora Avatar asked Jan 19 '26 14:01

leora


1 Answers

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..
    }
}
like image 72
Hans Passant Avatar answered Jan 22 '26 05:01

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!