Go语言中可以使用内置函数strings.Split()来将字符串分割为数组。语法如下:
strings.Split(string, sep)
其中,string为要分割的字符串,sep为分隔符。返回值为分割后的字符串数组。
示例:
s := "hello,world,how,are,you" arr := strings.Split(s, ",") fmt.Println(arr) //输出:[hello world how are you]
请注意,这个内置函数是在"strings"包中的,因此在使用之前需要引用此包。
使用方法:
import "strings"