最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Go 標準包 strings 學習(6) Join,LastIndex,LastIndexAny,LastIndexByte,L

2023-05-06 13:08 作者:取悅疾風  | 我要投稿

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ī)則

Go 標準包 strings 學習(6) Join,LastIndex,LastIndexAny,LastIndexByte,L的評論 (共 條)

分享到微博請遵守國家法律
金华市| 武穴市| 宜都市| 榆社县| 英德市| 淳化县| 扎兰屯市| 开远市| 云浮市| 丹棱县| 平定县| 池州市| 绥中县| 安平县| 遵化市| 台北市| 马公市| 专栏| 公安县| 达州市| 孙吴县| 怀安县| 汉源县| 华阴市| 离岛区| 青神县| 喀喇沁旗| 东海县| 武功县| 溧水县| 天峨县| 绥德县| 寻甸| 中牟县| 任丘市| 昭觉县| 吴桥县| 亳州市| 宕昌县| 崇阳县| 普洱|