Go 標準包 strings 學習(6) Join,LastIndex,LastIndexAny,LastIndexByte,L
https://pkg.go.dev/strings@go1.20.4#Join
func?Join
Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.
Join將其第一個參數(shù)的元素連接起來以創(chuàng)建單個字符串。分隔字符串sep放置在結(jié)果字符串的元素之間。
例子
輸出
foo, bar, baz
理解:將一個切片里面的數(shù)據(jù)轉(zhuǎn)為一整個字符串,并使用傳入的第二個string分割

func?LastIndex
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
LastIndex返回s中substr最后一個實例的索引,如果substr不存在于s中,則返回-1。
例子
輸出
0 3 -1
理解
傳入2個字符串,第一個是需要被搜索的字符串,第二個是需要在第一個字符串里面進行檢索的字符串,返回第二個字符串在第一個字符串中最后一次出現(xiàn)的下標位置

func?LastIndexAny
LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
LastIndexAny返回s中字符的任何Unicode碼點的最后一個實例的索引,如果s中沒有字符的Unicode碼點,則返回-1。
例子
輸出
4 8 -1
理解
返回第二個字符串里的任意一個字符,在第一個字符串中,最后一次出現(xiàn)的下標

func?LastIndexByte
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
LastIndexByte返回s中c的最后一個實例的索引,如果s中不存在c,則返回-1。
例子
輸出
10 8 -1
理解
返回輸入的字符在字符串中最后一次出現(xiàn)的下標位置

func?LastIndexFunc
LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.
LastIndexFunc返回滿足f(c)的最后一個Unicode碼點到s的索引,如果不滿足則返回-1。
例子
輸出
5 2 -1
理解
返回字符串在哪一個下標位置符合指定的規(guī)則