在 Go 中,我想检查以下字符串是否包含text/plain在字符串中。函数strings.Contains()总是返回false。
我的本地 go 版本是go1.14.3 windows/amd64,我的服务器版本是go1.13.3 linux/amd64
测试代码(play.golang.org/p/_ikCzWd6438)
var test = "text/plain; charset=utf-8"
fmt.Println("my string:", test)
fmt.Println("strings.Contains(text/plain)", strings.Contains("text/plain", test))
fmt.Println("strings.Contains(text)", strings.Contains("text", test))
fmt.Println("strings.Contains(charset)", strings.Contains("charset", test))
var test2 = strings.ReplaceAll(test, "/", "") // remove slash
fmt.Println("my second string:", test2)
fmt.Println("strings.Contains(textplain)", strings.Contains("textplain", test2))
fmt.Println("strings.Contains(text)", strings.Contains("text", test2))
fmt.Println("strings.Contains(charset)", strings.Contains("charset", test2))
输出
my string: text/plain; charset=utf-8
strings.Contains(text/plain) false
strings.Contains(text) false
strings.Contains(charset) false
my second string: textplain; charset=utf-8
strings.Contains(textplain) false
strings.Contains(text) false
strings.Contains(charset) false
那么为什么strings.Contains()总是返回'false'?
慕哥6287543
相关分类