切片字节与字符串转化

package test01

import (
	"fmt"
	"testing"
)

var datas []string

func TestYyy(t *testing.T) {
	fmt.Println(Add("abc")) //abc
	fmt.Println(datas)      //[abc]

}

func Add(str string) string {
	data := []byte(str) //[97,98,99]

	sData := string(data) //abc

	datas = append(datas, sData) //[abc]

	return sData
}

posted @ 2023-07-17 23:56  Bre-eZe  阅读(22)  评论(0)    收藏  举报