Back to questions
JuniorTheoryCommon
What does the program print?
package main
import (
"fmt"
"unicode/utf8"
)
func main() {
s := "héllo"
fmt.Println(len(s), utf8.RuneCountInString(s))
}6 5
- Expecting
5 5:lencounts bytes, not characters, andétakes two bytes in UTF-8, so the string is 6 bytes long. - Expecting two bytes per character for every letter: Go strings hold UTF-8, where each Latin letter takes one byte and
étakes two.
- What type and value does
s[1]have for this string? - What does
len([]rune(s))return, and why?