Case insensitive string comparison in Go

后端 未结 1 1284
面向向阳花
面向向阳花 2021-02-11 14:25

How do I compare strings in a case insensitive manner?

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

相关标签:
1条回答
  • 2021-02-11 15:00

    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"))
    }
    
    0 讨论(0)
提交回复
热议问题