55

How do I compare strings in a case insensitive manner?

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

user7610
  • 25,267
  • 15
  • 124
  • 150

2 Answers2

109

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"))
}
user7610
  • 25,267
  • 15
  • 124
  • 150
0

There is alternative to strings.EqualFold, there is bytes.EqualFold which work in same way

package main

import (
    "bytes"
    "fmt"
)

func main() {
    fmt.Println(bytes.EqualFold([]byte("Go"), []byte("go")))
}

https://golang.org/pkg/bytes/#EqualFold

user7610
  • 25,267
  • 15
  • 124
  • 150
kris
  • 979
  • 11
  • 15