How do I compare strings in a case insensitive manner?
For example, "Go" and "go" should be considered equal.
Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function. Example 1: This example uses toUpperCase() function to compare two strings.
The Go Language is case sensitive.
The best way to do a case insensitive comparison in JavaScript is to use RegExp match() method with the i flag.
CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.
https://golang.org/pkg/strings/#EqualFold is the function you are looking for. It is used like this (example from the linked documentation):
package main import ( "fmt" "strings" ) func main() { fmt.Println(strings.EqualFold("Go", "go")) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With