String Length Calculator
TX-04Paste text to see its length in characters, UTF-16 code units, Unicode code points and UTF-8 bytes, plus the number of words, lines and sentences. Each count is on its own line.
Runs in your browser. Nothing is uploaded.
Text
Counts
How to use it
- Paste or type your text into the input box, or open a text file.
- Read the counts in the output box. They update as you type.
- Compare Characters, UTF-16 code units, Code points and UTF-8 bytes to see which limit your system uses.
- Check Words, Lines and Sentences for the size of the text.
- Copy the counts or use Share link to keep the text in a link.
Why one string has several lengths
Text can be measured in different units. Characters are what a reader sees as one symbol. Code points are Unicode numbers, and one character can be several. UTF-16 code units are what JavaScript, Java and C# return as the string length. UTF-8 bytes are what the text takes up in a UTF-8 file, API payload or database column. The family emoji is 1 character, 5 code points, 8 UTF-16 code units and 18 UTF-8 bytes.
Which count to use
Use UTF-16 code units to compare with string.length in JavaScript or length() in Java. Use UTF-8 bytes for a byte limit, such as a database column, an HTTP header or a cloud field. Use code points for a count that matches Python's len() on a string. Use characters for what people see, as in a character limit on a form. SQL Server's LEN counts UTF-16 code units for nvarchar, and DATALENGTH counts bytes.
How words, lines and sentences are counted
Words and sentences use your browser's Unicode text rules for English, so punctuation alone is not a word and 3.14 is one word. Hyphenated words such as state-of-the-art count as several, and an abbreviation can end a sentence early, so treat these two as close, not exact. Lines are separated by line breaks, and one final line break does not add an empty line. Characters without spaces leaves out all whitespace.
Questions people ask
How do I count characters in a string?
Paste the text and read the Characters line. It counts what a reader sees as one symbol, so an emoji with several parts counts as 1. The same box shows code points, UTF-16 units and UTF-8 bytes if you need those instead.
What is the difference between code points and UTF-16 code units?
A code point is one Unicode number. UTF-16 stores code points above U+FFFF, such as most emoji, as two code units, so JavaScript's length counts them twice. Plain letters and digits are 1 of each.
How many bytes is my string in UTF-8?
Read the UTF-8 bytes line. ASCII characters take 1 byte, most accented letters 2, most Chinese, Japanese and Korean characters 3, and emoji 4. A string with 10 characters can be well over 10 bytes.
Why is the length different from what my database shows?
Databases measure different things. SQL Server's LEN for nvarchar counts UTF-16 units (and ignores trailing spaces) and DATALENGTH counts bytes, while MySQL's CHAR_LENGTH counts code points and LENGTH counts bytes. Compare your number to the matching line here.
How are words and sentences counted?
With your browser's Unicode text rules for English. Punctuation alone is not a word, and hyphenated words count as several. Sentences end at punctuation the rules recognize, so abbreviations can split one early. They are close estimates.
Do line breaks count as characters?
Yes. A line break is a character, one code point and one byte for a plain \n, or two for \r\n. The Lines count is separate and ignores one final line break.
About this tool
Characters are what a reader sees as one symbol, so a family emoji is 1. Code points are Unicode scalar values and that emoji is 5. UTF-16 code units are what JavaScript, Java and C# report as the string length, and it is 8 here. UTF-8 bytes are what the text takes in a UTF-8 file or database column, and it is 18. Words and sentences come from your browser's Unicode text rules for English, so hyphenated words count as several words and an abbreviation can end a sentence early. Lines count line breaks; a final line break does not add an empty line.