Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(3)Cut,CutPrefix,CutSuffix
官網(wǎng)
https://pkg.go.dev/strings@go1.20.3 作者:取悅疾風(fēng)?
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前后的文本。發(fā)現(xiàn)的結(jié)果報告sep是否出現(xiàn)在s中。如果sep沒有出現(xiàn)在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返回沒有提供的前導(dǎo)前綴字符串的s,并報告它是否找到了前綴。如果s不以prefix開頭,則CutPrefix返回s, false。如果prefix是空字符串,CutPrefix返回s, true。
說明
返回s字符串去除prefix字符串后的字符串,并返回是否找到

func?CutSuffix
和上一個差不多
返回s字符串去除suffix字符串后的字符串,并返回是否找到
本質(zhì)上都是返回一個string去除另一個string后的結(jié)果