someString := "one two three four "words := strings.Fields(someString)fmt.Println(words,len(words)) // [one two three four] 4 , N& a. ?. n" _2 H j" Q4 P8 h
演示: http : //play.golang.org/p/et97S90cIH& o% g1 G8 c+ t1 a7 g# s
从文档:) I2 {9 Y3 C8 E: c
func Fields(s string) []string8 d: a/ x3 T9 w0 N, j2 b
字段s每个实例围绕一个或多个连续空格字符拆分字符串,s如果 s 如果只包含空间,则返回 子字符串数组或空列表。