Junior — Middle
How can a text string be transformed into a sequence of runic characters?
sobes.tech AI
Answer from AI
In Go (Golang), to convert a string to a sequence of rune characters, you can use the rune type, which represents a Unicode code point. A string in Go is a sequence of bytes, and converting it to runes allows working with Unicode characters correctly.
Example of converting a string to a slice of runes:
package main
import (
"fmt"
)
func main() {
str := "Example"
runes := []rune(str) // convert string to slice of runes
for i, r := range runes {
fmt.Printf("rune %d: %c (code %U)\n", i, r, r)
}
}
As a result, you get each character of the string as a rune with its Unicode code point. This is useful for correctly processing characters, especially if the string contains multi-byte characters.