我[]byte从UDP套接字获得一个字节slice()并希望将其视为整数slice([]int32)而不更改底层数组,反之亦然.在C(++)中,我只是在指针类型之间转换; 我怎么在Go中这样做?
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".所以我必须检查字符串的格式.
有没有更好的办法?
[]uint8从 转换为的最佳方式是什么string?
我正在使用http://github.com/confluenceinc/confluence-kafka-go/kafka
从 kafka 读取事件。但它不返回纯字符串事件。它返回类型为 的事件[]uint8。我怎样才能将此事件从 转换[]uint8为string?
我有以下字节数组:
buf := make([]byte, 1)
var value int8
value = 45
buf[0] = value // cannot use type int8 as type []byte in assignment
Run Code Online (Sandbox Code Playgroud)
当我想将一个char值放入字节数组时,我得到了错误cannot use type int8 as type []byte in assignment.怎么了?我该怎么做呢?