String Length Online

Paste a string to check its length: the four numbers a length call can return, side by side.

A sample. Type or paste your own.

Sample: the counts of the text in grey above.

Length in UTF-16 units
16
Code points
13
Characters
11
UTF-8 bytes
26

More options a limit for length in utf-16 units

What the 4 counts mean

Lengths a program reports 3

  • Code points Numbered Unicode characters: 13 in the sample. The smiling face is 1. The astronaut is 3: an adult, a zero width joiner and a rocket.
  • Length in UTF-16 units What a length property reports where strings are held as UTF-16: 16 for the sample. The smiling face counts 2, the astronaut 5, and everything else 1 each.
  • UTF-8 bytes What a byte-counting length returns for text stored as UTF-8: 26 in the sample. The é and the à take 2 each, the smiling face 4 and the astronaut 11.

The length a reader sees 1

  • Characters What a reader counts: 11 in the sample. The astronaut is 1, and so is an ñ typed as n plus a combining tilde.

How it works

This string length counter shows what a length call returns for your text: UTF-16 code units first, then code points, characters and UTF-8 bytes. The sample is 16 long by the first and 13, 11 or 26 by the others.

Read the full guide

Which length your code reports

JavaScript and Java report UTF-16 code units, the first number. Python’s len counts code points. Swift’s count gives characters. Where a length is counted in bytes, read the last number, which is true for text stored as UTF-8.

Why an emoji has a length of 2

The smiling face is one code point and one character. UTF-16 stores any code point above U+FFFF as a pair of units, so its length reads 2, and UTF-8 spends 4 bytes on it.

Accents and styled letters

An é is 1 unit and 2 bytes. A letter from the bold text generator sits above U+FFFF, so a four-letter word in it has a length of 8 and takes 16 bytes.

Questions and answers

Is this an online strlen?

Yes: read UTF-8 bytes. In C, strlen returns the number of bytes before the first null character, and in PHP it returns the length of the string in bytes, not characters. For the sample, stored as UTF-8, both give 26.

How do I calculate the length of a string online?

Paste or type the string and this string length calculator shows all four lengths as you type. Quotation marks pasted with it are counted too, so leave them out unless they are part of the string.

Does string length count spaces?

Yes. A space or a tab adds 1 to all four numbers, at the ends of the string as well as inside it. An empty string has a length of 0.

Is a string length checker the same as a character counter?

For most everyday text the two numbers match. They part at emoji and joined characters: a length check counts what is stored, the character counter counts what a reader sees, and the astronaut is 1 character with a length of 5.