An alternative to standard CSV implementation of Go (https://github.com/golang/go/tree/master/src/encoding/csv), and modified by Tushar Dwivedi (https://github.com/tushar2708/altcsv), to support some more delimiters, and a few non-standard(?) CSV formats.
In addition to standard encoding/csv functionality,
- You can use a custom quoting characters for reading and writing CSV, by giving setting
Quote
to a desired rune. - You can force quote all fields, by setting
AllQuotes
flag astrue
go get github.com/tushar2708/altcsv
Or, using glide:
glide get github.com/tushar2708/altcsv
fileRdr, _ = os.Open("/tmp/custom_csv_file.txt")
csvRdr := altcsv.NewReader(fileRdr)
csvRdr.Comma = ';' // use ; as "comma"
csvRdr.Quote = '|' // use | as "quote"
content := csvReader.ReadAll()
headers = []string{"hero_name", "alter_ego", "identity"}
fileWtr, _ := os.Create("/tmp/all_quotes_csv_file.txt")
csvWtr := altcsv.NewWriter(csvH)
csvWtr.Quote = '|' // use | as "quote"
csvWtr.AllQuotes = true // surround each field with '|'
csvWtr.Write(headers)
csvWtr.Write([]string{"Spider-Man", "Peter Parker", "Secret Identity"})
csvWtr.Write([]string{"Captain America", "Steven Rogers", "Public Identity"})
csvWtr.Write([]string{"Thor", "Thor Odinson", "No dual Identity"})
csvWtr.Flush()
fileWtr.Close()
- Supporting custom
Quote
character. - Supporting
AllQuotes
flag. - Supporting reading or writing headers.
- Reading & writing Row as a map[string]string, with header fields as keys.