Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive string comparison in Go

How do I compare strings in a case insensitive manner?

For example, "Go" and "go" should be considered equal.

like image 552
user7610 Avatar asked May 12 '15 16:05

user7610


People also ask

How do you compare two string cases insensitive?

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.

Is Go Language case-sensitive?

The Go Language is case sensitive.

Which will do case insensitive comparison of string contents?

The best way to do a case insensitive comparison in JavaScript is to use RegExp match() method with the i flag.

Are string comparisons case-sensitive?

CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.


1 Answers

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")) } 
like image 180
user7610 Avatar answered Oct 14 '22 13:10

user7610