CalcHive

String Length Analyzer

Analyze string length in multiple ways: JavaScript length, Unicode code points, UTF-8 bytes, and grapheme clusters. Essential for database field validation and API limits.

Examples

Simple ASCII

In:Hello, World!

Emoji string

In:πŸš€πŸŒŸπŸ”₯πŸ‘πŸΌπŸ‡ΊπŸ‡Έ

Multi-byte characters

In:γ“γ‚“γ«γ‘γ―δΈ–η•Œ β€” CafΓ© naΓ―vetΓ©
0
JS .length

UTF-16 code units

0
Code Points

Unicode characters

0
UTF-8 Bytes

Byte size in UTF-8

0
UTF-16 Bytes

Byte size in UTF-16

0
Grapheme Clusters

Visible characters

How to Use String Length Analyzer

  1. Type or paste your text in the input area.
  2. All length metrics update in real time as you type.
  3. Click the Copy button on any metric to copy its value to your clipboard.
  4. Try the examples to see how emoji and multi-byte characters affect different length measurements.

Understanding String Length

String length is not as straightforward as counting visible characters. Different programming languages, databases, and protocols measure strings in different ways. This tool shows you five distinct measurements so you can pick the right one for your use case.

JavaScript .length counts UTF-16 code units. This is what you get when you call str.length in JavaScript or TypeScript. Characters outside the Basic Multilingual Plane (BMP) use surrogate pairs and count as 2.

Unicode code points count the actual Unicode characters. This is equivalent to [...str].length in modern JavaScript and correctly handles surrogate pairs.

UTF-8 bytes is the number of bytes needed to encode the string in UTF-8, which is the dominant encoding on the web. ASCII characters use 1 byte, while emoji can use up to 4 bytes each.

Grapheme clusters represent what a user perceives as a single character. Flag emoji, family emoji, and characters with combining marks are each one grapheme cluster despite being composed of multiple code points.

Frequently Asked Questions

Related Tools