Go中不区分大小写的字符串比较 [英] Case insensitive string comparison in Go

查看:515
本文介绍了Go中不区分大小写的字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以不区分大小写的方式比较字符串?

例如,Go和go应该被认为是相等的。

解决方案

https://golang.org/pkg/字符串/#EqualFold 是你正在寻找的功能。它是这样使用的(例子来自链接文档):

  package main 

import(
fmt
strings


func main(){
fmt.Println(strings.EqualFold(Go,go ))
}


How do I compare strings in a case insensitive manner?

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

解决方案

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

这篇关于Go中不区分大小写的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆