How to convert uint8 slice to string
byte
is an alias for uint8
, which means that a slice of uint8
) (aka []uint8
) is also a slice of byte
(aka []byte
).
And byte slices and strings are directly convertible, due to the fact that strings are backed by byte slices:
myByteSlice := []byte{ ... } // same as myByteSlice := []uint8{ ... }
myString := string(myByteSlice) // myString is a string representation of the byte slice
myOtherSlice := []byte(myString) // Converted back to byte slice