Iterate over Go string characters using a range loop to get correct Unicode rune handling.
Use a range loop over the string to iterate over its runes (Unicode characters), which handles multi-byte characters correctly.
s := "Hello, δΈη"
for i, r := range s {
fmt.Printf("Index: %d, Rune: %c\n", i, r)
}
If you specifically need bytes (not recommended for non-ASCII), range over a []byte slice instead.
In Go, strings are sequences of bytes, but they represent Unicode characters called 'runes'. Using a standard for loop with range automatically handles the complex math of converting those bytes into readable characters, even for emojis or foreign languages. Think of it like reading a book where some words take up more space on the page; range ensures you stop at the end of each word, not just every inch of paper.