golang strings.EqualFold()方法
strings.EqualFold()方法
Golang语言中的strings模块中的EqualFold()方法,可以用于判断两个utf-8编码的字符串是否相等,不区分大小写。
EqualFold()语法
func strings.EqualFold(s string, t string) bool
go源码对EqualFold()方法的介绍:
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
参数
参数 | 描述 |
---|---|
s | go的string字符串类型 |
t | go的string字符串类型 |
返回值
go的bool类型,如果两个字符串相等,则返回true,如果不同,则返回false。
strings.EqualFold()方法实例代码
package main
import (
"fmt"
"strings"
)
func main() {
var t1 bool = strings.EqualFold("x1y1z1.com", "X1Y1Z1.COM")
t2 := strings.EqualFold("a", "a")
t3 := strings.EqualFold("b", "c")
fmt.Println(t1)
fmt.Println(t2)
fmt.Println(t3)
}
//命令行输入运行go文件的命令,比如:go run test.go,得到输出:
true
true
false