golang 字符串比较是否相等的方法示例
程序员文章站
2022-06-04 20:38:07
golang字符串比较的三种常见方法fmt.println("go"=="go")fmt.println("go"=="go")fmt.println(strings.compare("go","go...
golang字符串比较的三种常见方法
fmt.println("go"=="go") fmt.println("go"=="go") fmt.println(strings.compare("go","go")) fmt.println(strings.compare("go","go")) fmt.println(strings.equalfold("go","go"))
输出
true
false
-1
0
true
1,自建方法“==”,区分大小写,最简单的方法
2,compare函数,区分大小写,自建方法“==”的速度要比compare快,下面是注释
/ compare is included only for symmetry with package bytes. // it is usually clearer and always faster to use the built-in // string comparison operators ==, <, >, and so on. func compare(a, b string) int
3,比较utf-8编码在小写的条件下是否相等,不区分大小写,下面是注释
// equalfold reports whether s and t, interpreted as utf-8 strings, // are equal under unicode case-folding. func equalfold(s, t string) bool
到此这篇关于golang 字符串比较是否相等的方法示例的文章就介绍到这了,更多相关golang 字符串比较相等内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 用结构体解析Pascal字符串