如何将uint8转换为字符串 [英] How to convert uint8 to string
本文介绍了如何将uint8转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
http://play.golang.org/p/BoZkHC8_uA
我想将uint8转换为字符串,但不知道怎么做.
I want to convert uint8 to string but can't figure out how.
package main
import "fmt"
import "strconv"
func main() {
str := "Hello"
fmt.Println(str[1]) // 101
fmt.Println(strconv.Itoa(str[1]))
}
这给了我prog.go:11: cannot use str[1] (type uint8) as type int in function argument
[process exited with non-zero status]
This gives me prog.go:11: cannot use str[1] (type uint8) as type int in function argument
[process exited with non-zero status]
有什么主意吗?
推荐答案
简单地对其进行转换:
fmt.Println(strconv.Itoa(int(str[1])))
这篇关于如何将uint8转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文