【发布时间】:2013-10-13 22:25:21
【问题描述】:
http://play.golang.org/p/BoZkHC8_uA
我想将 uint8 转换为字符串,但不知道怎么做。
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]
有什么想法吗?
【问题讨论】:
-
如果您正在寻找有关 uint8 ([]uint8) 切片的信息,请查看此答案的第一部分:stackoverflow.com/a/28848879/1364759
-
string(u)或fmt.Sprintf("%s", u)将[]uint8设置为刺痛。见stackoverflow.com/a/62725637/12817546。[]uint8("abc")将字符串设置为[]uint8。见stackoverflow.com/a/62740786/12817546。
标签: go