Intermediate 8 min

Unicode and UTF-8

Unicode identifies text characters, while UTF-8 defines how their values are encoded as bytes.

How it works

A text field is often read in terms of visible symbols, but a network limit can count bytes. The same string can satisfy one limit and fail the other. If the user sees a character limit, count characters in the way that matches the text you show.

Walk through an example

The letter A uses one byte in UTF-8. Characters outside the ASCII range can use several bytes. Some visible symbols combine multiple Unicode code points.

What to watch for

Character count, byte count, and visible symbol count can differ. Choose your unit before implementing a limit or slicing text.

Check your understanding

How long is Aé in bytes?

See the example and explanation
Worked example
Given UTF-8 encodes A as one byte and é as two bytes.
Answer 3 bytes

Add one byte for A and two for é.

Open practice problem
Next lessonValue copies and shared references