1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package main
import ( "encoding/csv" "fmt" "log" "strings" )
func main() { s := `名前,年齢,身長,体重 Tanaka,31,190cm,97kg Suzuki,46,180cm,79kg Matsui,45,188cm,95kg ` r := csv.NewReader(strings.NewReader(s))
records, err := r.ReadAll() if err != nil { if e, ok := err.(*csv.ParseError); ok { n := 0 switch e.Err { case csv.ErrBareQuote: n = 1 case csv.ErrQuote: n = 2 case csv.ErrFieldCount: n = 3 } log.Fatal("\nエラー: ", n, "\n", e.Err, "\nStartLine:", e.StartLine, "\nLine:", e.Line, "\nColumn:", e.Column) } log.Fatal(err) }
fmt.Println(records) }
|