Skip to main content

String Length Calculator

Calculate string length instantly. Count visible characters, Unicode code points, UTF-16 code units, UTF-8 bytes, and text without whitespace.

Characters
0
User-perceived grapheme clusters
Unicode Code Points
0
Unicode scalar values in the string
UTF-16 Code Units
0
The value returned by JavaScript string.length
UTF-8 Bytes
0
Size after UTF-8 encoding
Without Whitespace
0
Graphemes after spaces, Tabs, and line breaks

Your tool input is processed locally in your browser—not uploaded to or stored by Bitty Coder. Privacy Policy

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

  1. Type or paste a string, open a .txt file, or select Example.
  2. Read Characters for the number of user-perceived characters.
  3. 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:

MeasurementLength
Characters7
Unicode Code Points7
UTF-16 Code Units8
UTF-8 Bytes10
Without Whitespace6

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

MeasurementWhat it countsCommon use
CharactersUser-perceived grapheme clustersText shown to people
Unicode Code PointsUnicode valuesUnicode-aware data processing
UTF-16 Code UnitsJavaScript string unitsJavaScript and Java length checks
UTF-8 BytesEncoded bytesAPIs, files, databases, and network payloads
Without WhitespaceCharacters after removing whitespaceCompact 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 APITypical result
JavaScript string.lengthUTF-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.