在 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 slashfmt.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-8strings.Contains(text/plain) falsestrings.Contains(text) falsestrings.Contains(charset) falsemy second string: textplain; charset=utf-8strings.Contains(textplain) falsestrings.Contains(text) falsestrings.Contains(charset) false那么为什么strings.Contains()总是返回'false'?
- 1 回答
- 0 关注
- 272 浏览
添加回答
举报
0/150
提交
取消