Text & Writing
Counting words by whitespace
Trim the text, then split it on runs of whitespace. Each resulting piece is one word, regardless of the punctuation it carries.
Last updated
The Formula
words = number of whitespace-separated tokens
Trim the text, then split it on runs of whitespace. Each resulting piece is one word, regardless of the punctuation it carries.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| t | Token | token | A maximal run of characters with no whitespace inside. |
| W | Word count | words | How many such tokens the text contains. |
What Each Symbol Means
ttoken
Token
A maximal run of characters with no whitespace inside.
Wwords
Word count
How many such tokens the text contains.
See It Worked With Real Numbers
A formula on its own does not tell you which number goes where. The how to count words 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 Words, filed under Everyday Life. Every number the guide produces comes from substituting into this one line.
Common Questions
What is the formula for Counting words by whitespace?
The formula for Counting words by whitespace is words = number of whitespace-separated tokens. Trim the text, then split it on runs of whitespace. Each resulting piece is one word, regardless of the punctuation it carries.
What units should I use with Counting words by whitespace?
Substitute t in token, W in words. 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 Counting words by whitespace?
Assuming every tool counts the same way. Word, Google Docs and a plain text counter tokenise differently around hyphens, slashes and contractions. A few words of drift between them is normal rather than a bug in either.