How to Check If two Strings are Equal in a Case-Insensitive Manner in Go
Created
Modified
Using strings.EqualFold Function
The strings.EqualFold()
function 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.
See the following example:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.EqualFold("HeLLO", "hello"))
// It even works with Unicode.
fmt.Println(strings.EqualFold("A̐É", "a̐é"))
}
true true