What is a string length calculator?
A string length calculator measures how much text a string contains. The answer depends on what “length” means: a visible character, a Unicode code point, a UTF-16 code unit, or an encoded byte can produce different totals for the same text.
This calculator displays those common measurements together so you can use the value that matches a form, API, database, programming language, or file-size constraint.
How to calculate string length
- Type or paste a string, open a
.txtfile, or select Example. - Read Characters for the number of user-perceived characters.
- Use the code-point, UTF-16, UTF-8, or whitespace-free result when your technical constraint uses that measurement.
Results update immediately. There is no Calculate button.
String length example
Enter:
Hello 👋
The results are:
| Measurement | Length |
|---|---|
| Characters | 7 |
| Unicode Code Points | 7 |
| UTF-16 Code Units | 8 |
| UTF-8 Bytes | 10 |
| Without Whitespace | 6 |
The waving-hand Emoji is one visible character and one Unicode code point, but JavaScript stores it as two UTF-16 code units and UTF-8 encodes it as four bytes.
Characters, code points, code units, and bytes
| Measurement | What it counts | Common use |
|---|---|---|
| Characters | User-perceived grapheme clusters | Text shown to people |
| Unicode Code Points | Unicode values | Unicode-aware data processing |
| UTF-16 Code Units | JavaScript string units | JavaScript and Java length checks |
| UTF-8 Bytes | Encoded bytes | APIs, files, databases, and network payloads |
| Without Whitespace | Characters after removing whitespace | Compact content checks |
Does string length include spaces and newlines?
Yes. Characters, code points, code units, and bytes include spaces, Tabs, and line breaks because they are part of the string. Use Without Whitespace when those characters should be excluded.
A line break normally counts as one character, but its UTF-8 byte count can depend on whether the text uses LF or CRLF line endings.
Why can one Emoji have different lengths?
Some Emoji use a surrogate pair in UTF-16. Others combine several code points with variation selectors, skin-tone modifiers, or zero-width joiners while still appearing as one character.
For example, a family Emoji can be one grapheme cluster but several Unicode code points and even more UTF-16 code units. Characters follows grapheme clusters, while the other results expose the underlying representations.
Common string length uses
- Check form fields and API parameter limits.
- Plan database column sizes.
- Measure UTF-8 request, message, or file content.
- Create boundary values for software tests.
String length in programming languages
Language APIs do not always use the same definition:
| Language or API | Typical result |
|---|---|
JavaScript string.length | UTF-16 code units |
Python len(text) | Unicode code points |
Java string.length() | UTF-16 code units |
PHP strlen() | Bytes |
PHP mb_strlen() | Characters in the selected encoding |
Always match the tool result to the definition used by the system you are testing.
String length FAQ
What is the length of an empty string?
Zero for every measurement.
Are Unicode code points the same as visible characters?
Not always. Combining marks and joined Emoji can use multiple code points while appearing as one character.
Why does JavaScript count some Emoji as two?
JavaScript string.length counts UTF-16 code units. A code point outside the Basic Multilingual Plane uses two code units.
How is UTF-8 byte length calculated?
The string is encoded as UTF-8 and the resulting bytes are counted. ASCII characters use one byte, while many non-ASCII characters use more.