Go 字符串与字节数组互相转换

Go About 247 words

[]byte()

字符串转字节数组

str := "Hello Golang"
fmt.Println([]byte(str))
// [72 101 108 108 111 32 71 111 108 97 110 103]

string()

字节数组转字符串

bytes := []byte{72, 101, 108, 108, 111, 32, 71, 111, 108, 97, 110, 103}
fmt.Println(string(bytes))
// Hello Golang
Views: 4,837 · Posted: 2020-10-31

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh