Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\main::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/cms.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\main::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
go string []byte相互转换 - 互联网笔记

略微加速

略速 - 互联网笔记

go string []byte相互转换

2021-03-09 leiting (1848阅读)

标签 Golang

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[:])

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3