Go strings are usually, but not necessarily, UTF-8 encoded. In case they are Unicode strings, the term "char [acter]" is quite complex and there is no general / unique bijection of runes (code points) and Unicode characters.
In any case, you can easily work with code points (runes) in a slice and use indices in it using a transformation:
package main import "fmt" func main() { utf8 := "Hello, δΈη" runes := []rune(utf8) fmt.Printf("utf8:% 02x\nrunes: %#v\n", []byte(utf8), runes) }
Also here: http://play.golang.org/p/qWVSA-n93o
Note. Often, the desire to access Unicode characters by index is a design error. Most text data is processed sequentially.
source share