golang bytes to string
In Go, you can convert a byte slice to a string using the string() function. Here's an example:
package main
import (
"fmt"
)
func main() {
byteSlice := []byte{71, 111, 32, 76, 97, 110, 103}
str := string(byteSlice)
fmt.Println(str) // Output: Go Lang
}
In this example, we have a byte slice byteSlice that contains ASCII values representing the characters "Go Lang". We use the string() function to convert the byte slice to a string and then print the result. The output will be "Go Lang"
原文地址: http://www.cveoy.top/t/topic/it83 著作权归作者所有。请勿转载和采集!