If you CSV is simple, as in does not have multi-line values in columns, \n in line ending — then you can create your own wrapper around io.Reader that counts number of \n before returning to caller []bytes.
-- Nikolay On Friday, April 9, 2021 at 1:50:10 AM UTC+8 peterGo wrote: > Dan, > > For Go 1.17: > > encoding/csv: add the ability to get the line number of a record #44221 > https://github.com/golang/go/issues/44221 > > Peter > > On Thursday, April 8, 2021 at 12:36:27 PM UTC-4 [email protected] wrote: > >> My need is similar to issue #26679 but not the same. >> >> I am using 1.15.8 >> >> I have a need for the "current line number" when reading a csv file (with >> Reader.Read() ) so that I can report errors in the data (not a csv >> parsing error but errors in the data in the csv file). In my case, a >> comment character is being used to allow my user to provide comments in the >> file for easier maintainability of their csv data. Because of comments in >> the file the record number and line number are not the same so any >> reporting of errors to my user cannot point to any specific line number in >> the file for the data error ... I have to either give info on the record to >> my user or tell them the non-commented line number (neither being a >> user-friendly option as they have to look through the file to see where the >> real error is instead of going to a specific line number). >> >> Any way to get the true (starting) line number of the current record as a >> file is being read using the Reader.Read() function? >> >> Thanks >> Dan >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/845d27a4-46af-4623-acb8-bcd49cab3605n%40googlegroups.com.
