Golang strings.EqualFold() 函数及示例
strings.EqualFold() 函数 在 Golang 中,该函数判断 s 和 t 是否相等。它们会被视为 UTF-8 编码的字符串,在 Unicode 折叠大小写(即较为通用的大小写不敏感)的情况下是否相等。
语法:
func EqualFold(s1, s2 string) bool
这里的 s1 和 s2 都是字符串。
返回值: 它将返回布尔值。
示例 1:
// Golang program to illustrate the
// strings.EqualFold() Function
package main
// 导入 fmt 和 strings 包
import("fmt"
"strings")
// 调用主函数
func main()
{
// 不区分大小写比较并返回真。
fmt.Println(strings.EqualFold("Geeks", "Geeks"))
// 不区分大小写比较并返回真。
fmt.Println(strings.EqualFold("computerscience",
"computerscience"))
}
输出:
true
true
示例 2:
// Golang program to illustrate the
// strings.EqualFold() Function
package main
// 导入 fmt 和 strings 包
import("fmt"
"strings")
// 调用主函数
func main()
{
// 不区分大小写比较并返回真。
fmt.Println(strings.EqualFold("Geeks", "geeks"))
// 不区分大小写比较并返回真。
fmt.Println(strings.EqualFold("COMPUTERSCIENCE",
"computerscience"))
}
输出:
true
true