go strings.ContainsRune()方法

strings.ContainsRune()方法

语法

func ContainsRune(s string, r rune) bool

strings.ContainsRune()方法可以用来判断字符串s中是否包含Unicode的编码值r。


go源码ContainsRune()方法的介绍:

ContainsRune reports whether the Unicode code point r is within s.

参数

参数描述
sstring字符串类型
rrune类型数值

返回值

如果字符串s包含Unicode的编码值,则返回true,否则返回false。


strings.ContainsRune()方法实例代码

func main() {
	t := strings.ContainsRune("笨鸟工具,x1y1z1.com", 31528)
	fmt.Println(t)
}
//命令行输入运行go文件的命令,比如:go run test.go,得到输出:
true

实例代码提示

“笨”字的Unicode编码为31528。需要查询字符串的Unicode编码值,可参考:unicode编码转换工具在线



全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.