This seems to be what you're actually trying to do:
characters := "some text"
for i := 0; i < len(characters); i++ {
b := characters[i]
fmt.Println(b)
}
Your code is confusing (and doesn't compile), but you appear to want to iterate over the string, and for the element you are currently on, convert the character to a byte and print it. If so, you don't need (or want) to convert anything to a []byte
.
If you don't want to iterate byte by byte but instead character by character, use a range
loop. It iterates over rune
s:
characters := "s?me spécial text"
for _, r := range characters {
char := string(r)
b := []byte(char)
fmt.Println(char, b)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…