Search⌘ K
AI Features

Puzzle 3 Explanation: ASCII Encoding

Explore how ASCII encoding works and why certain characters in Go strings take multiple bytes. Understand the difference between byte length and rune count and learn to use the unicode/utf8 package for accurate string length measurement.

We'll cover the following...

Try it yourself

Try executing the code below to see the result for yourself.

Go (1.16.5)
package main
import (
"fmt"
)
func main() {
city := "Kraków"
fmt.Println(len(city))
}

Explanation

If we count the number of characters in “Kraków,” we’ll count six. However, they are considered seven characters. Why?? The reason is … history.

In the beginning, computers were invented by English-speaking countries: the UK and the US. Initially, ...