Standard library / encoding/csv

encoding/csv.Reader.Read()

Read one CSV record. A wrong field count may return the record and an error; a syntax error may return partial fields. Clean end returns io.EOF. Expected stdout: '[a b]\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) Read() (record []string, err error)

Return Value

(record []string, err error)

Record (possibly partial) and error.

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\nc,d\n"))  x, e := r.Read()  must(e)  fmt.Println(x)}
Go Reference