<分区>
在 python 中,没有分隔符的 split()
函数会拆分空白/制表符等,并返回一个列表,其中所有 空格被移除
>>> "string with multiple spaces".split()
['string', 'with', 'multiple', 'spaces']
如何在 go
中实现类似的功能?
package main
import "fmt"
import "strings"
func main() {
s := "string with multiple spaces"
lst := strings.Split(s, " ")
for k, v := range lst {
fmt.Println(k,v)
}
}
上面给出了
0 string
1
2
3
4 with
5 multiple
6
7
8
9
10
11 spaces
我想将每个字符串保存在 lst[0]
、lst[1]
、lst[2]
和lst[3]
。这可以做到吗?谢谢