Standard library / encoding/csv

encoding/csv.Writer.Write()

Encode one record, quoting fields as required. A nil return does not guarantee all bytes reached the underlying writer; flush and check errors. Expected stdout: '"a,b",c\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) Write(record []string) error

Parameters & Attributes

NameTypeDescription
record[]stringFields in a single CSV record.

Return Value

error

Nil on success; otherwise an operation-specific error.

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)  must(w.Write([]string{"a,b", "c"}))  w.Flush()  must(w.Error())  fmt.Print(b.String())}
Go Reference