golang 字符串分割(分割字符串)

package main

import (
	"fmt"
	"strings"
)

func main() {
	str := "-100 123 200"

    //指定分隔符
    countSplit := strings.Split(str, " ")
    fmt.Println(countSplit, len(countSplit))

    //指定分割符号,指定分割次数
    countSplit = strings.SplitN(str, " ", 2)
    fmt.Println(countSplit, len(countSplit))
}

返回值:均为切片

运行结果:

[-100 123 200] 3

[-100 123 200] 2

你可能感兴趣的:(Golang)