Text & Writing
Character length
The length of a string is the count of its code units, which includes spaces, punctuation and line breaks but counts an emoji as more than one.
Last updated
The Formula
characters = number of code units in the string
The length of a string is the count of its code units, which includes spaces, punctuation and line breaks but counts an emoji as more than one.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| s | Text | string | The string being measured. |
| C | Character count | characters | How many code units the string contains. |
What Each Symbol Means
sstring
Text
The string being measured.
Ccharacters
Character count
How many code units the string contains.
See It Worked With Real Numbers
A formula on its own does not tell you which number goes where. The how to count characters page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.
Where This Formula Appears
This equation is the working core of How To Count Characters, filed under Everyday Life. Every number the guide produces comes from substituting into this one line.
Common Questions
What is the formula for Character length?
The formula for Character length is characters = number of code units in the string. The length of a string is the count of its code units, which includes spaces, punctuation and line breaks but counts an emoji as more than one.
What units should I use with Character length?
Substitute s in string, C in characters. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.
What is a common mistake when using Character length?
Forgetting that spaces count. A headline of twelve short words can pass 60 characters on the spaces alone. Count with spaces when the limit is about display width.