I am writing a package to read CSV files in Go, and I need to open CSV files which may be coded in different formats (such as UTF8, Latin1 or others). Is there a way to specify the encoding format of the CSV file to read?
Package csv
import "encoding/csv"func NewReader
func NewReader(r io.Reader) *ReaderNewReader returns a new Reader that reads from r.
Provide an io.Reader to csv.NewReader that maps the CSV file character set to Unicode UTF-8.
For example,
import (
"encoding/csv"
"golang.org/x/text/encoding/charmap"
)
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
rdr := csv.NewReader(charmap.ISO8859_15.NewDecoder().Reader(file))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With