引用自 https://stackoverflow.com/questions/31220421/convert-a-byte-to-a-string-in-go
需求
bytes := [4]byte{1,2,3,4}
str := convert(bytes)
//str == "1,2,3,4"
解答
func convert( b []byte ) string {
s := make([]string,len(b))
for i := range b {
s[i] = strconv.Itoa(int(b[i]))
}
return strings.Join(s,",")
}
学习:strconv
Package strconv implements conversions to and from string representations of basic data types.
分清conversion itoa(90 --> “90”)
与 representation (90 --> ‘a’)