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]))
}
Run Code Online (Sandbox Code Playgroud)
这给了我 prog.go:11: cannot use str[1] (type uint8) as type int in function argument
[process exited with non-zero status]
任何的想法?
我想在golang中将字符串转换为整数.但我不知道字符串的格式.例如,"10"- > 10,"65.0"- > 65,"xx"- > 0,"11xx" - > 11,"xx11" - > 0
我做了一些搜索并找到了strconv.ParseInt().但它无法处理"65.0".所以我必须检查字符串的格式.
有没有更好的办法?
我在网上发布了一个rune()在golang 中使用该功能的功能,但我很难查找它是什么.我正在阅读教程,对文档缺乏经验,因此很难找到我要找的东西.
具体来说,我试图了解为什么这会失败......
fmt.Println(rune("foo"))
Run Code Online (Sandbox Code Playgroud)
而这不是
fmt.Println([]rune("foo"))
Run Code Online (Sandbox Code Playgroud)