五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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ó)家法律
昌黎县| 太仓市| 姜堰市| 鄂托克前旗| 萨嘎县| 师宗县| 措美县| 宜良县| 定安县| 万山特区| 阿坝县| 沙坪坝区| 尼木县| 定结县| 连云港市| 同江市| 灯塔市| 灵寿县| 柏乡县| 社旗县| 镇江市| 县级市| 寿宁县| 广宗县| 襄城县| 垣曲县| 青田县| 固阳县| 敦煌市| 城步| 威远县| 长宁区| 隆子县| 河西区| 专栏| 平顶山市| 乌兰浩特市| 宣威市| 剑河县| 和平区| 西盟|