Standard library / encoding/csv

encoding/csv.Writer

Buffered CSV serializer. Configure Comma and UseCRLF before writing. Flush and check Error after Write, or use WriteAll. Expected stdout: '"a;b\\r\\n"\n'.

Formal Syntax & Structure

go syntaxgo
type Writer struct {  Comma   rune  UseCRLF bool  // Has unexported fields.}

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/csv"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var b bytes.Buffer  w := csv.NewWriter(&b)  w.Comma = ';'  w.UseCRLF = true  must(w.WriteAll([][]string{{"a", "b"}}))  fmt.Printf("%q\n", b.String())}
Go Reference