使用 strings 包的 Contains 函数是最高效的方式,因为它使用了 Rabin-Karp 字符串匹配算法:
import "strings"
func main() {
str := "hello world"
if strings.Contains(str, "world") {
fmt.Println("Found")
} else {
fmt.Println("Not found")
}
}
使用 strings 包的 Contains 函数是最高效的方式,因为它使用了 Rabin-Karp 字符串匹配算法:
import "strings"
func main() {
str := "hello world"
if strings.Contains(str, "world") {
fmt.Println("Found")
} else {
fmt.Println("Not found")
}
}
本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=2127
还没有评论,快来说点什么吧~