golang string to bytes
To convert a Go string to bytes, you can use the []byte type conversion. Here's an example:
package main
import "fmt"
func main() {
str := "Hello, World!"
bytes := []byte(str)
fmt.Println(bytes) // [72 101 108 108 111 44 32 87 111 114 108 100 33]
}
In the above example, the []byte conversion is used to convert the string str to a byte slice called bytes. The fmt.Println statement is used to print the byte slice. Each character in the string is represented by its ASCII value in the byte slice
原文地址: http://www.cveoy.top/t/topic/it8W 著作权归作者所有。请勿转载和采集!