Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 如何将uint8数组转换为字符串_Go_Type Conversion - Fatal编程技术网

Go 如何将uint8数组转换为字符串

Go 如何将uint8数组转换为字符串,go,type-conversion,Go,Type Conversion,将[]uint8转换为字符串的最佳方式是什么 我正在使用 阅读卡夫卡的事件。但它不会返回纯字符串事件。 它返回类型为[]uint8的事件 如何将此事件从[]uint8转换为字符串?,这意味着uint8的片段aka[]uint8也是byte aka[]byte的片段 字节片和字符串可以直接转换,因为字符串由字节片支持: myByteSlice := []byte{ ... } // same as myByteSlice := []uint8{ ... } myString := stri

将[]uint8转换为字符串的最佳方式是什么

我正在使用

阅读卡夫卡的事件。但它不会返回纯字符串事件。 它返回类型为[]uint8的事件 如何将此事件从[]uint8转换为字符串?

,这意味着uint8的片段aka[]uint8也是byte aka[]byte的片段

字节片和字符串可以直接转换,因为字符串由字节片支持:

myByteSlice := []byte{ ... }     // same as myByteSlice := []uint8{ ... }
myString := string(myByteSlice)  // myString is a string representation of the byte slice
myOtherSlice := []byte(myString) // Converted back to byte slice

看这里:只需Stringuint8切片。请注意,这是一个切片,而不是数组。