Indexing string as chars

go, string, unicode

Solution

The simplest solution is to convert it to an array of runes :

var runes = []rune("someString")

Note that when you iterate on a string, you don't need the conversion. See this example from Effective Go :

for pos, char := range "日本語" {
    fmt.Printf("character %c starts at byte position %d\n", char, pos)
}

This prints

character 日 starts at byte position 0
character 本 starts at byte position 3
character 語 starts at byte position 6

Problem

The elements of strings have type byte and may be accessed using the usual indexing operations. How can I get element of string as char ? "some"[1] -> "o"

Original source