鸿蒙传说
是:对于字符串切片:package mainimport "encoding/csv"import "os"func main() { wr := csv.NewWriter(os.Stdout) wr.Write([]string{"test1", "test2", "test3"}) wr.Flush()}对于 int (或任何切片):package mainimport ( "encoding/csv" "fmt" "os" "strings")func main() { A := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} // []string{"test1", "test2", "test3"} st := strings.Fields(strings.Trim(fmt.Sprint(A), "[]")) wr := csv.NewWriter(os.Stdout) wr.Write(st) wr.Flush() // 0,1,2,3,4,5,6,7,8,9}其他方式:package mainimport ( //"encoding/csv" "fmt" "strings")func main() { A := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} st := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(A)), ", "), "[]") fmt.Println(st) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}如果您的数据不是 int 将其转换为字符串切片,则使用 strings.Join 函数。