阅读(2889)
赞(8)
GoFrame gstr-包含判断
2022-04-11 15:14:50 更新
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
}