How do I convert a single byte to a slice of bytes in Go?
I have tried this in a few different ways however none of them have worked. I keep getting an error stating: cannot convert charBytes[i] (type byte) to type []byte
.
The only working method I have found for this so far is to get a character from a string, cast it as a string then recast it as a byte array.
characters := "some text"
for i := 0; len(characters); i++ {
var b []byte = []byte(string(characters[i]))
fmt.Println(b)
}