GoFrame gstr-包含判断
Contains
- 说明:
Contains
返回字符串str
是否包含子字符串substr
,区分大小写。
- 格式:
Contains(str, substr string) bool
func ExampleContains() {
{
var (
str = `Hello World`
substr = `Hello`
result = gstr.Contains(str, substr)
)
fmt.Println(result)
}
{
var (
str = `Hello World`
substr = `hello`
result = gstr.Contains(str, substr)
)
fmt.Println(result)
}
// Output:
// true
// false
}
ContainsI
- 说明:
ContainsI
校验substr
是否在str
中,不区分大小写。
- 格式:
ContainsI(str, substr string) bool
func ExampleContainsI() {
var (
str = `Hello World`
substr = "hello"
result1 = gstr.Contains(str, substr)
result2 = gstr.ContainsI(str, substr)
)
fmt.Println(result1)
fmt.Println(result2)
// Output:
// false
// true
}
ContainsAny
- 说明:
ContainsAny
校验s
中是否包含chars
。
- 格式:
ContainsAny(s, chars string) bool
func ExampleContainsAny() {
{
var (
s = `goframe`
chars = "g"
result = gstr.ContainsAny(s, chars)
)
fmt.Println(result)
}
{
var (
s = `goframe`
chars = "G"
result = gstr.ContainsAny(s, chars)
)
fmt.Println(result)
}
// Output:
// true
// false
}