I am new to golang, try to do something like this:
bytes := [4]byte{1,2,3,4}
str := convert(bytes)
//str == "1,2,3,4"
searched a lot, really no idea how to do this.
I know this will not work:
str = string(bytes[:])
I am new to golang, try to do something like this:
bytes := [4]byte{1,2,3,4}
str := convert(bytes)
//str == "1,2,3,4"
searched a lot, really no idea how to do this.
I know this will not work:
str = string(bytes[:])
Similar to inf's suggestion but allowing for commas:
fmt.Sprintf("%d,%d,%d,%d", bytes[0], bytes[1], bytes[2], bytes[3])
Not the most efficient way to implement it, but you can simply write:
to be called by:
hex.EncodeToString(input)
may work for you.If you are not bound to the exact representation then you can use
fmt.Sprint
:On the other side if you want your exact comma style then you have to build it yourself using a loop together with
strconv.Itoa
.