Standard library / encoding/csv

CSV quoted fields

A CSV field containing a delimiter, newline or quote needs CSV quoting; embedded double quotes are doubled. Use the CSV parser rather than splitting on commas. Expected stdout: '"a,b" "say \\"hi\\""\n'.

Formal Syntax & Structure

go syntaxgo
"a,b","say ""hi"""

Working Example

Example Snippetgo
package main
import (  "encoding/csv"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  r := csv.NewReader(strings.NewReader("\"a,b\",\"say \"\"hi\"\"\"\n"))  x, e := r.Read()  must(e)  fmt.Printf("%q %q\n", x[0], x[1])}
Go Reference