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

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

Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(7)Map,Repeat,Replace

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

上次標(biāo)題太長了,后面的一個(gè)方法名沒寫出來,但是標(biāo)題還是要寫的,無非就是少寫幾個(gè)方法

后面就先給文章一個(gè)目錄吧

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

Map,Repeat,Replace

開始

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


func?Map

Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.

Map返回字符串s的副本,其中所有字符都根據(jù)映射函數(shù)進(jìn)行了修改。如果映射返回負(fù)值,則從字符串中刪除該字符,不進(jìn)行替換。

沒看懂...

例子

輸出

'Gjnf oevyyvt naq gur fyvgul tbcure...

理解

案例里面演示了一個(gè)類似加密的操作

這個(gè)方法的應(yīng)用暫時(shí)沒想到

func?Repeat

Repeat returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

Repeat返回一個(gè)由字符串s的count個(gè)副本組成的新字符串。

如果count為負(fù)或(len(s) * count)的結(jié)果溢出,則會產(chǎn)生恐慌。

舉例

輸出

banana

理解

就是復(fù)制count次,然后組裝成1個(gè)新的字符串

func?Replace

Replace returns a copy of the string s with the first n 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. If n < 0, there is no limit on the number of replacements.

Replace返回字符串s的副本,其中舊的前n個(gè)不重疊的實(shí)例替換為new。如果old為空,它匹配字符串的開頭和每個(gè)UTF-8序列之后,為k-rune字符串產(chǎn)生最多k+1個(gè)替換。如果n < 0,則替換次數(shù)沒有限制。

案例

輸出

oinky oinky oink

moo moo moo

理解

就是在s里面把old的替換成new字符串,可以指定替換多少個(gè),要換多少n就寫多少,如果要全替換就寫-1

Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(7)Map,Repeat,Replace的評論 (共 條)

分享到微博請遵守國家法律
益阳市| 卓尼县| 马山县| 安化县| 东乡族自治县| 固始县| 芦山县| 文成县| 阿合奇县| 申扎县| 贵定县| 自贡市| 罗田县| 盐城市| 榆林市| 阜城县| 岚皋县| 兴和县| 嵊泗县| 台南县| 方城县| 洞口县| 苍溪县| 吉水县| 大安市| 桓仁| 韶山市| 鸡西市| 武功县| 西畴县| 武平县| 景东| 嫩江县| 苍梧县| 洛川县| 瓮安县| 奉新县| 凌海市| 连平县| 福建省| 景宁|