在源代码中:
// Contains returns true if substr is within s.
func Contains(s, substr string) bool {
return Index(s, substr) >= 0
}
// ContainsAny returns true if any Unicode code points in chars are within s.
func ContainsAny(s, chars string) bool {
return IndexAny(s, chars) >= 0
}
Run Code Online (Sandbox Code Playgroud)
唯一的区别似乎是substr和the Unicode code points in chars.我写了一些测试来测试它们.他们的行为似乎完全相同.我不明白何时使用哪个.
Xia*_*Pei 11
我认为两个功能完全不同.包含用于检测字符串是否包含子字符串.ContainsAny用于检测字符串是否包含提供的字符串中的任何字符.