//Golang: 根据ascii码表将 []byte 转换为 string
//以下函数入参为int型切片数组,函数返回根据ASCII表转换后的字符串。
import (
"unsafe"
"reflect"
)
func BytesToString(b []byte) string {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := reflect.StringHeader{bh.Data, bh.Len}
return *(*string)(unsafe.Pointer(&sh))
}
Golang:根据ascii码表将int型 []byte 转换为 string
最新推荐文章于 2024-05-12 20:22:36 发布