2

I have the following problem. I have to read csv files that are delimited by '|', and some fields have large json strings in which some contain '|'. The fields are enclosed in single-quotes. How can I specify in GOLANG that the fields are enclosed in single quotes.

This is how it is setup right now:

fx := csv.NewReader(fz)

fx.Comma = '|'
fx.LazyQuotes = true
fx.FieldsPerRecord = 16

I don't see anything in GODOCS options for enclosure rules. Does anyone have a workaround for this ?

1 Answer 1

5

You can't, however, luckily Go is written in, well, Go.

You could copy $GOROOT/src/pkg/encoding/csv/reader.go, then modify line 274, 289, 297 and 303 to use '\'' instead of '"' and you're good to go.

Sign up to request clarification or add additional context in comments.

6 Comments

Good to know! But I can't do this in production :D
Why not? you can copy it to your own package and use it just fine. instead of import "encoding/csv" use import "your-project-path/csv".
Yes, it works! But I feel kind of awkward doing this :))
I think I'm going to make a feature request about this.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.