Case insensitive string comparison in Go

后端 未结 1 778
旧巷少年郎
旧巷少年郎 2021-02-11 14:32

How do I compare strings in a case insensitive manner?

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

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-11 15:14

    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)
提交回复
热议问题