Go 標(biāo)準(zhǔn)包 strings 學(xué)習(xí)(2) ContainsAny,ContainsRune,Count
2023-04-21 13:20 作者:取悅疾風(fēng) | 我要投稿
func?ContainsAny
ContainsAny reports whether any Unicode code points in chars are within s.
翻譯
ContainsAny報(bào)告字符中的Unicode碼位是否在s內(nèi)。
舉例
結(jié)果
理解
前面字符串包含后面字符串里面的任意一個(gè)字符就返回true,空串返回false

func?ContainsRune
ContainsRune reports whether the Unicode code point r is within s.
翻譯
ContainsRune報(bào)告Unicode碼點(diǎn)r是否在s內(nèi)。
這里point是指針,不是點(diǎn)
舉例
結(jié)果
理解
返回字符串里面是否包含某個(gè)阿斯克碼(ASCII),這里的阿斯克碼使用數(shù)字表示

func?Count
Count counts the number of non-overlapping instances of substr in s. If substr is an empty string, Count returns 1 + the number of Unicode code points in s.
翻譯
Count計(jì)算s中substr的非重疊實(shí)例的個(gè)數(shù)。如果substr為空字符串,Count返回1 + s中Unicode碼點(diǎn)的個(gè)數(shù)。
舉例
結(jié)果
理解
返回第二個(gè)字符串在第一個(gè)字符串里面出現(xiàn)了幾次
標(biāo)簽: