Go 普通字符串打印问题,println 和 string() 包裹一下有什么区别?
为什么一个简单的字符串我使用内置函数 Println 可以打印出来,但使用 string 包了一下就打不出来了
回复
1个回答

test
2024-07-12
看前面的 if
,openCapcha 应该不是一个字符串,而是一个整形。整形转字符串直接得到的是这个这个码位的 Unicode 字符:
Conversions to and from a string type
Converting a signed or unsigned integer value to a string type yields a string containing the UTF-8 representation of the integer. Values outside the range of valid Unicode code points are converted to "\uFFFD".
string('a') // "a" string(-1) // "\ufffd" == "\xef\xbf\xbd" string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8" type myString string myString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
这个转换应该不是你需要的。
你需要的应该是 strconv.Itoa
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容