I am new to Go and trying to do something like this:
bytes := [4]byte{1,2,3,4}
str := convert(bytes)
//str == "1,2,3,4"
I searched a lot and really have no idea how to do this.
I know this will not work:
str = string(bytes[:])
I am new to Go and trying to do something like this:
bytes := [4]byte{1,2,3,4}
str := convert(bytes)
//str == "1,2,3,4"
I searched a lot and really have no idea how to do this.
I know this will not work:
str = string(bytes[:])
Not the most efficient way to implement it, but you can simply write:
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,",")
}
to be called by:
bytes := [4]byte{1,2,3,4}
str := convert(bytes[:])