go SplitAfter()

SplitAfter()方法语法

func SplitAfter(s, sep string) []string

go源码对SplitAfter()方法的介绍:

SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.

If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s.

If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and sep are empty, SplitAfter returns an empty slice.

It is equivalent to SplitAfterN with a count of -1.

即,golang的标准库strings中的SplitAfter()方法,可以将字符串s按分隔符seq之后的一个位置进行分割,返回一个以字符串为元素的string切片(不修改原字符串),具体可参考下方的实例代码。


strings.SplitAfter()方法实例代码

func main() {
	var str_slice []string = strings.SplitAfter("笨鸟工具,x1y1z1.com", "1")
	fmt.Println(str_slice)
}

(mac环境下)运行go文件,得到输出:

[笨鸟工具,x1 y1 z1 .com]

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.