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

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

Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(8)ReplaceAll,Split,SplitAfter

2023-05-15 13:25 作者:取悅疾風(fēng)  | 我要投稿

繼續(xù)

本次學(xué)習(xí)

ReplaceAll,Split,SplitAfter

https://pkg.go.dev/strings@go1.20.4#ReplaceAll


func?ReplaceAll

ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

ReplaceAll返回字符串s的副本,其中所有不重疊的old實(shí)例替換為new。如果old為空,它匹配字符串的開(kāi)頭和每個(gè)UTF-8序列之后,為k-rune字符串產(chǎn)生最多k+1個(gè)替換。

案例

輸出

moo moo moo

理解

沒(méi)啥好說(shuō)的,作用和方法名一樣用new把s里面的old全替換掉

func?Split

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

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

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

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

To split around the first instance of a separator, see Cut.

????

將切片拆分為所有以sep分隔的子字符串,并返回分隔符之間的子字符串切片。

如果s不包含sep且sep不為空,Split返回一個(gè)長(zhǎng)度為1的切片,其中唯一的元素是s。

如果sep為空,Split在每個(gè)UTF-8序列之后進(jìn)行分割。如果s和sep都為空,Split返回一個(gè)空片。

它相當(dāng)于計(jì)數(shù)為-1的SplitN。

要圍繞分隔符的第一個(gè)實(shí)例進(jìn)行拆分,請(qǐng)參見(jiàn)切割。

案例

????

輸出

["a" "b" "c"]

["" "man " "plan " "canal panama"]

[" " "x" "y" "z" " "]

[""]

理解

將s用sep拆分成切片

func?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.

SplitAfter在sep的每個(gè)實(shí)例之后將s切片為所有子字符串,并返回這些子字符串的一個(gè)切片。

如果s不包含sep且sep不為空,則SplitAfter返回一個(gè)長(zhǎng)度為1的切片,其中唯一的元素是s。

如果sep為空,SplitAfter在每個(gè)UTF-8序列之后進(jìn)行分割。如果s和sep都為空,則SplitAfter返回一個(gè)空切片。

它相當(dāng)于計(jì)數(shù)為-1的SplitAfterN。

案例1

輸出1

["a," "b," "c"]

案例2

輸出2

["a," "b," "c," "," ""]


Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(8)ReplaceAll,Split,SplitAfter的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
湖口县| 利津县| 宜兰市| 汉沽区| 远安县| 芜湖县| 腾冲县| 临清市| 滕州市| 道孚县| 得荣县| 柳河县| 启东市| 台南县| 宁蒗| 萨迦县| 黄陵县| SHOW| 西林县| 荣成市| 保定市| 阿坝县| 阿拉善右旗| 台北市| 常熟市| 如东县| 荣成市| 山阳县| 大关县| 静宁县| 宁南县| 玛纳斯县| 赤壁市| 新蔡县| 马鞍山市| 张家港市| 会宁县| 无棣县| 黔东| 利辛县| 陇川县|