🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 解析 csv ``` in := `first_name,last_name,username "Rob","Pike",rob Ken,Thompson,ken "Robert","Griesemer","gri" ` r := csv.NewReader(strings.NewReader(in)) //r.Comma = ';' // 指定分隔符 //r.Comment = '#' // 指定注释 for { record, err := r.Read() if err == io.EOF { break } if err != nil { log.Fatal(err) } fmt.Println(record) } // Output: // [first_name last_name username] // [Rob Pike rob] // [Ken Thompson ken] // [Robert Griesemer gri] ``` ## 数组转 csv ``` records := [][]string{ {"first_name", "last_name", "username"}, {"Rob", "Pike", "rob"}, {"Ken", "Thompson", "ken"}, {"Robert", "Griesemer", "gri"}, } w := csv.NewWriter(os.Stdout) w.WriteAll(records) // calls Flush internally if err := w.Error(); err != nil { log.Fatalln("error writing csv:", err) } ```