golang 中的string 和 []byte 相互转换
string to [] byte
var strhello string = "hello world"
var bytehello []byte = []byte(strhello)
fmt.Printf("%s [%x]\n", bytehello, bytehello)
输出:
hello world [68656c6c6f20776f726c64]
[]byte to string
var bytehello []byte = []byte{'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'}
var stringhello string = string(bytehello[:])
fmt.Printf("%s [%x]\n", stringhello, stringhello)
输出:
hello world [68656c6c6f20776f726c64]
本文暂时没有评论,来添加一个吧(●'◡'●)