golang 判断字符串是否包含
子串
可以使用 strings 包中的 Contains 函数来判断字符串是否包含子串。
示例代码:
package main
import (
"fmt"
"strings"
)
func main() {
str := "hello world"
subStr := "world"
if strings.Contains(str, subStr) {
fmt.Printf("%s contains %s\n", str, subStr)
} else {
fmt.Printf("%s does not contain %s\n", str, subStr)
}
}
输出:
hello world contains world
原文地址: https://www.cveoy.top/t/topic/eol9 著作权归作者所有。请勿转载和采集!