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

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

分享到微博請遵守國家法律
会东县| 甘孜| 洛阳市| 青海省| 邢台市| 开远市| 四平市| 岳池县| 手机| 保康县| 怀安县| 阳朔县| 图片| 葫芦岛市| 上林县| 烟台市| 大英县| 东宁县| 弥勒县| 越西县| 改则县| 黎川县| 泌阳县| 临海市| 龙川县| 民丰县| 青冈县| 洮南市| 宁南县| 乳山市| 威海市| 沅陵县| 安阳市| 东城区| 江永县| 开江县| 娱乐| 金山区| 汉沽区| 赤峰市| 山阴县|