Strings, Bytes and Runes
Strings are UTF-8 bytes. len counts bytes. Range over a string gives runes.
Example
package main
import "fmt"
func main() {
s := "héllo"
fmt.Println(len(s), len([]rune(s)))
for i, r := range "hé" {
fmt.Println(i, string(r))
}
}Result
6 5 0 h 1 é
Exercise
Count characters.
len([](s))
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.