Case insensitive string comparison in Go

user7610 picture user7610 · May 12, 2015 · Viewed 23k times · Source

How do I compare strings in a case insensitive manner?

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

Answer

user7610 picture user7610 · May 12, 2015

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"))
}