1. Self-built method "==", case-sensitive, the simplest method
fmt.Println("go"=="go") fmt.Println("GO"=="go")
Output result:
true false
2. Compare Function, case-sensitive, faster than the self-built method "=="
fmt.Println(strings.Compare("GO","go")) fmt.Println(strings.Compare("go","go"))
Output result:
-1 0
3. Compare UTF-8 encoding under lowercase conditions Whether they are equal or not, case-insensitive
fmt.Println(strings.EqualFold("GO","go"))
Output result:
true
Recommended related articles and tutorials: golang tutorial
The above is the detailed content of How to compare strings for equality in golang. For more information, please follow other related articles on the PHP Chinese website!