From cc37097164607637ffc4677790cceb56d5e7afe1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 30 Jul 2024 00:44:03 +0800 Subject: [PATCH] library: bufio, encoding/csv --- README.md | 2 ++ _cmptest/csvdemo/csv.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 _cmptest/csvdemo/csv.go diff --git a/README.md b/README.md index 5762e3dd..f9c3fcf4 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,7 @@ Here are the Go packages that can be imported correctly: * [flag](https://pkg.go.dev/flag) * [sort](https://pkg.go.dev/sort) * [bytes](https://pkg.go.dev/bytes) +* [bufio](https://pkg.go.dev/bufio) * [strings](https://pkg.go.dev/strings) * [strconv](https://pkg.go.dev/strconv) * [path](https://pkg.go.dev/path) @@ -295,6 +296,7 @@ Here are the Go packages that can be imported correctly: * [encoding/hex](https://pkg.go.dev/encoding/hex) * [encoding/base32](https://pkg.go.dev/encoding/base32) * [encoding/base64](https://pkg.go.dev/encoding/base64) +* [encoding/csv](https://pkg.go.dev/encoding/csv) * [regexp](https://pkg.go.dev/regexp) * [regexp/syntax](https://pkg.go.dev/regexp/syntax) diff --git a/_cmptest/csvdemo/csv.go b/_cmptest/csvdemo/csv.go new file mode 100644 index 00000000..d4beec09 --- /dev/null +++ b/_cmptest/csvdemo/csv.go @@ -0,0 +1,30 @@ +package main + +import ( + "encoding/csv" + "fmt" + "io" + "log" + "strings" +) + +func main() { + in := `first_name,last_name,username +"Rob","Pike",rob +Ken,Thompson,ken +"Robert","Griesemer","gri" +` + r := csv.NewReader(strings.NewReader(in)) + + for { + record, err := r.Read() + if err == io.EOF { + break + } + if err != nil { + log.Fatal(err) + } + + fmt.Println(record) + } +}