如何以不区分大小写的方式比较Go中的两个字符串值?

How to compare two strings with case insensitivity? For example: Both "a" == "a" and "a" == "A" must return true.

Found the answer. Convert both strings to either lowercase or upper case and compare. import "strings" strings.ToUpper(str1) == strings.ToUpper(str2)

There is a strings.EqualFold() function which performs case insensitive string comparison.

For example:

fmt.Println(strings.EqualFold("aa", "Aa"))
fmt.Println(strings.EqualFold("aa", "AA"))
fmt.Println(strings.EqualFold("aa", "Ab"))

Output (try it on the Go Playground):

true
true
false