国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ó)家法律
古交市| 宿州市| 湛江市| 夏津县| 康平县| 白玉县| 叶城县| 甘洛县| 南漳县| 徐汇区| 祁阳县| 巩留县| 资讯 | 阳东县| 呼图壁县| 延边| 鹿邑县| 曲麻莱县| 扶绥县| 阳东县| 汝南县| 康马县| 乌审旗| 礼泉县| 咸阳市| 象州县| 焉耆| 渝中区| 芒康县| 阳西县| 清河县| 广宁县| 措美县| 通辽市| 晋州市| 镇雄县| 甘南县| 英德市| 图木舒克市| 固原市| 上虞市|