Go 标准包 strings 学习(3)Cut,CutPrefix,CutSuffix
官网
https://pkg.go.dev/strings@go1.20.3 作者:取悦疾风
func Cut
Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.
在sep的第一个实例周围切割切片s,返回sep前后的文本。发现的结果报告sep是否出现在s中。如果sep没有出现在s中,则Cut返回s, "", false。
没看懂...
举例
输出
理解
返回前一个字符串是否包含后一个字符串,并且输出前一个字符串在删除后面的字符串后的前面,后面2部分

func CutPrefix
CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty string, CutPrefix returns s, true.
翻译
CutPrefix返回没有提供的前导前缀字符串的s,并报告它是否找到了前缀。如果s不以prefix开头,则CutPrefix返回s, false。如果prefix是空字符串,CutPrefix返回s, true。
说明
返回s字符串去除prefix字符串后的字符串,并返回是否找到

func CutSuffix
和上一个差不多
返回s字符串去除suffix字符串后的字符串,并返回是否找到
本质上都是返回一个string去除另一个string后的结果