6

go string []byte相互转换

 3 years ago
source link: https://studygolang.com/articles/10526?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

go string []byte相互转换

jinjiashan · 2017-07-30 13:28:57 · 37463 次点击 · 预计阅读时间不到 1 分钟 · 不到1分钟之前 开始浏览    
这是一个创建于 2017-07-30 13:28:57 的文章,其中的信息可能已经有所发展或是发生改变。

string 不能直接和byte数组转换

string可以和byte的切片转换

1,string 转为[]byte

var str string = "test"

var data []byte = []byte(str)

2,byte转为string

var data [10]byte 

byte[0] = 'T'

byte[1] = 'E'

var str string = string(data[:])


有疑问加站长微信联系(非本文作者)

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:1006366459


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK