0PricingLogin
Go Academy · Lesson

encoding/csv

Read and write CSV.

What Is CSV

CSV (comma-separated values) stores tabular data as plain text, one record per line, fields separated by commas. Go's encoding/csv package reads and writes it.

Reading from a String

Create a reader from any io.Reader. strings.NewReader wraps a string so we can demo without a file.

package main

import (
	"encoding/csv"
	"fmt"
	"strings"
)

func main() {
	r := csv.NewReader(strings.NewReader("a,b,c"))
	rec, _ := r.Read()
	fmt.Println(rec)
}

All lessons in this course

  1. encoding/json Recap
  2. encoding/xml
  3. encoding/csv
  4. gob and Binary Encoding
← Back to Go Academy