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

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
始兴县| 房产| 茂名市| 正宁县| 卫辉市| 荔浦县| 科技| 南昌市| 乌兰浩特市| 合川市| 彰化县| 沙湾县| 合阳县| 乌审旗| 怀来县| 华阴市| 介休市| 格尔木市| 增城市| 沾益县| 房产| 高要市| 汾阳市| 寿光市| 宣威市| 天长市| 鹤峰县| 赫章县| 澜沧| 德州市| 县级市| 望奎县| 揭东县| 台南县| 蚌埠市| 遂川县| 娄底市| 苍溪县| 筠连县| 威信县| 丹棱县|