Strings, Bytes and Runes

A Go string is a read-only row of bytes. One visible character can use 1 to 4 of them.

The idea

Think of a string as a strip of tape with numbered cells. Plain English letters take one cell each. A letter like “é” needs two cells and an emoji needs four, because Go stores text as UTF-8.

So len(s) counts cells (bytes), not characters. A rune is Go’s word for one character (a Unicode code point). []rune(s) and for i, r := range s walk the string character by character instead of byte by byte.

Watch it work

Try it

Common mistakes