strings.Split 是 Go 语言中的一个函数,用于将字符串按照指定的分隔符进行切割,并返回切割后的子字符串数组。
使用方法如下:
package main
import (
"fmt"
"strings"
)
func main() {
str := "hello world"
arr := strings.Split(str, " ")
fmt.Println(arr) // 输出:[hello world]
}
在上述示例中,我们将字符串 “hello world” 使用空格作为分隔符进行切割,得到了一个包含两个子字符串 “hello” 和 “world” 的切片。
内容由零声教学AI助手提供,问题来源于学员提问




