func CaseInSensitiveCompareCompare(src, dest string) bool { if strings.Compare(strings.ToLower(src), strings.ToLower(dest)) == 0 { return true } else { return false } } jeffrey@hacker ~/Desktop/hello $ time go run main.go real 0m0.426s user 0m0.015s sys 0m0.000s 4.4.3 使用Equa...
读取文件然后使用==进行比较funcReadAndCaseInSensitiveBasicCompare(fileName, deststring)bool{returnreader.ReadFileAndCompare(fileName, dest, CaseInSensitiveBasicCompare) }// ReadAndCaseInSensitiveCompareCompare 不区分大小写。读取文件然后使用strings.Compare进行比较funcReadAndCaseInSensitiveCompareCompare(fileName, ...
return reader.ReadFileAndCompare(fileName, dest, CaseInSensitiveBasicCompare) } // ReadAndCaseInSensitiveCompareCompare 不区分大小写。读取文件然后使用strings.Compare进行比较 func ReadAndCaseInSensitiveCompareCompare(fileName, dest string) bool { return reader.ReadFileAndCompare(fileName, dest, CaseInSensit...
strings.Compare()略显快一些。 4.4 不区分大小写时的耗时 4.4.1 使用==时的耗时 funcCaseInSensitiveBasicCompare(src, deststring)bool{ifstrings.ToLower(src) == strings.ToLower(dest) {returntrue}else{returnfalse} } jeffrey@hacker ~/Desktop/hello $ time go run main.go real 0m0.423s user 0m0...
Compare 和 EqualFold 区别 EqualFold是比较UTF-8编码在小写的条件下是否相等,不区分大小写 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 // EqualFold reports whether s and t, interpreted as UTF-8 strings, // are equal under Unicode case-folding. func EqualFold(s, t string) bool ...
func CaseInSensitiveCompareCompare(src, dest string) bool { if strings.Compare(strings.ToLower(src), strings.ToLower(dest)) == 0 { return true } else { return false } } 1. 2. 3. 4. 5. 6. 7. jeffrey@hacker ~/Desktop/hello ...
String compare in GO Check if a string contains another string in GO Split a string by delimiter in Go Get all the words from a sentence Join a string by delimiter or a separator in Go Check if string begins with a prefix in Go ...
10ms 6.25% 75.00% 10ms 6.25% | github.com/valyala/fasthttp.caseInsensitiveCompare ---+--- 10ms 100% | runtime.mallocgc 10ms 6.25% 81.25% 10ms 6.25% | runtime.memclrNoHeapPointers ---+--- 10ms 100% | time.Time.AppendFormat 10ms 6.25% 87.50% 10ms 6.25% | runtime.memmove...
Go compare stringsStrings are compared with the == operator. Case-insensitive comparisons are performed with the EqualFold function. comparing.go package main import ( "fmt" "strings" ) func main() { w1 := "Aikido" w2 := "aikido" if w1 == w2 { fmt.Println("the strings are equal") ...
TheComparefunction compare two strings lexicographically. To compare two strings in a case-insensitive manner, we use theEqualFoldfunction. comparing.go package main import ( "fmt" "strings" ) func main() { w1 := "falcon" w2 := "Falcon" ...