Go: Convert string to rune slice (array)

Converting a string to a slice of runes yields a slice whose elements are the Unicode code points of the string.

s := "abc日"
r := []rune(s)
fmt.Printf("%v\n", r)
fmt.Printf("%U\n", r)
// Output:
// [97 98 99 26085]
// [U+0061 U+0062 U+0063 U+65E5]

Comments

Be the first to comment!