func SplitAfterN(s, sep string, n int) []string
如果sep为空字符,Split会将s切分成每一个unicode码值一个字符串。参数n决定返回的切片的数目:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 2))
fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 1))
fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 0))
fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", -1))
}
// Output:
// ["a," "b,c"]
// ["a,b,c"]
// []
// ["a," "b," "c"]