Go语言strings模块中的Contains方法,用于判断参数指定的字符串是否包含某个子串。
func strings.Contains(s string, substr string) bool
go源码对Contains()方法的介绍:
Contains reports whether substr is within s.
参数 | 描述 |
---|---|
s | string字符串类型 |
substr | string字符串 |
go语言的bool类型,如果字符串s包含substr子串,则返回true,否则返回false。
func main() {
var T bool = strings.Contains("笨鸟工具,x1y1z1.com", "工具")
fmt.Println(T)
F := strings.Contains("这里是go语法栏目", "计算机")
fmt.Println(F)
}
//命令行输入运行go文件的命令,比如:go run test.go,得到输出:
true
false
全栈编程 / go语法(可向下滚动):
Copyright © 2022-2023 笨鸟工具 x1y1z1.com All Rights Reserved.