s := strings.Split("", "")
fmt.Println(s, len(s))
s = strings.Split("abc,abc", "")
fmt.Println(s, len(s))
s = strings.Split("", ",")
fmt.Println(s, len(s))
s = strings.Split("abc,abc", ",")
fmt.Println(s, len(s))
s = strings.Split("abc,abc", "|")
fmt.Println(s, len(s))
fmt.Println(len(""))
fmt.Println(len([]string{""}))
str := ""
fmt.Println(str[0])
运行结果:
[] 0 //返回空数组
[a b c , a b c] 7 //返回7个数组元素
[] 1 //返回一个包含空字符元素的数组, 数组长度是1
[abc abc] 2
[abc,abc] 1
0
1
panic: runtime error: index out of range
有疑问加站长微信联系(非本文作者)