Runes, Bytes and Unicode
A string is a read only sequence of bytes. A rune is a Unicode code point. Indexing gives a byte, while ranging gives runes.
Example
package main
import (
"fmt"
"unicode"
)
func main() {
s := "héllo"
fmt.Println(len(s), len([]rune(s)), s[1])
for i, r := range "hé" {
fmt.Print(i, ":", string(r), " ")
}
fmt.Println()
fmt.Println(unicode.IsUpper('G'), string(unicode.ToUpper('a')))
}Result
6 5 195 0:h 1:é true A
Exercise
Type for a Unicode character.
var r = 'a'
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.