gocarina / gocsv

The GoCSV package aims to provide easy CSV serialization and deserialization to the golang programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use quotes and delimiter?

michaelwijnands opened this issue · comments

Hi,

I know I can create a custom CSV reader with: gocsv.SetCSVReader and that I can then assign a Comma:

gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {
		r := csv.NewReader(in)
		r.Comma = ';'
		return r
	})

However, I would also like to allow quotes in my file which should be possible with LazyCSVReader.
I tried to combine them but Comma doesn't exist for LazyCSVReader.

gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {
		r := gocsv.LazyCSVReader(in)
		r.Comma = ';'
		return r
	})

which results in:
Unresolved reference 'Comma'

How to achieve this?

The documentation says:

LazyCSVReader returns a lazy CSV reader, with LazyQuotes and TrimLeadingSpace.

So just add r.LazyQuotes = true to your custom CSV reader. LazyCSVReader is just a wrapper.