Case insensitive string comparison in Go

百般思念 提交于 2019-12-05 09:53:58

问题


How do I compare strings in a case insensitive manner?

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


回答1:


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


来源:https://stackoverflow.com/questions/30196780/case-insensitive-string-comparison-in-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!