在Go语言中,可以使用strings.ToLower()函数将字符串转换为小写形式,然后进行比较。下面是一个示例代码:

package main

import (
	"fmt"
	"strings"
)

func main() {
	str1 := "Hello"
	str2 := "hello"

	// 将字符串转换为小写形式,然后比较
	if strings.ToLower(str1) == strings.ToLower(str2) {
		fmt.Println("字符串相等")
	} else {
		fmt.Println("字符串不相等")
	}
}

运行以上代码,输出结果为字符串相等

golang if 判断两个字符串是否相等 不区分大小写

原文地址: http://www.cveoy.top/t/topic/hKFa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录