Golang中byte数组转string

发布于 2021-04-04  231 次阅读


package main
import (
	"fmt"
	"unsafe"
)
type bytes []byte
//非线程安全地
func (bytes) tostring(bs []byte) string {
	return *(*string)(unsafe.Pointer(&bs))
}
func main() {
	s := "你好呀"
	n := []byte(s)
	fmt.Println(toString(n))
}