Skip to content

Instantly share code, notes, and snippets.

@auycro
Created March 17, 2014 05:24
Show Gist options
  • Save auycro/9594386 to your computer and use it in GitHub Desktop.
Save auycro/9594386 to your computer and use it in GitHub Desktop.
CSVParser
package main
import (
"encoding/csv"
"fmt"
"io"
"os"
)
func main() {
file, err := os.Open("test.csv")
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
reader := csv.NewReader(file)
RowNum := 0
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("%d:",RowNum)
for i:=0;i<len(record);i++{
fmt.Print(record[i]+",") // record has the type []string
}
fmt.Println()
RowNum = RowNum+1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment