String Length, Bytes and Safe Truncation

Find out how long a string really is in every unit that matters, and cut it to a limit without breaking a character in half.

Funziona nel tuo browser. I tuoi file non lasciano mai il dispositivo. Scopri come verificarlo

…

Come si usa

  1. 1
    Paste the text

    Any language or emoji.

  2. 2
    Read the counts

    Characters, code points, bytes, units.

  3. 3
    Check the limits

    SMS, titles, file names and more.

  4. 4
    Inspect characters

    Code points and bytes per character.

  5. 5
    Set a truncation limit

    Choose the unit and ellipsis.

  6. 6
    Copy the result

    Safely truncated text.

Informazioni su questo strumento

The length of a string depends on who is counting. A person sees one character in a family emoji, JavaScript reports 11 because it counts UTF-16 units, Python counts 7 code points, a database column in bytes sees 25, and an SMS gateway charges by GSM-7 septets or UCS-2 segments. Getting this wrong truncates names in the middle of an accent, leaves broken emoji at the end of previews, overflows byte-limited fields such as bcrypt's 72-byte input or a 255-byte file name, and turns one text message into three. This tool counts every unit at once: graphemes (user-perceived characters), code points, UTF-16 units, UTF-8, UTF-16 and UTF-32 bytes, words, lines and SMS segments. It checks your text against common limits, shows each character with its code points and byte sizes, and truncates to any length in any unit while keeping whole graphemes, with an optional ellipsis and word boundary.

The units explained

- Graphemes: what readers see as one character, including combining accents, skin-tone modifiers and flags. - Code points: Unicode scalar values; Python's len and most databases' character counts use these. - UTF-16 units: what JavaScript, Java and C# string length report; characters outside the Basic Multilingual Plane count as two. - UTF-8 bytes: storage and network size; ASCII is 1 byte, accented Latin 2, most Asian scripts 3 and emoji 4 or more.

SMS segments

Text that uses only the GSM-7 alphabet fits 160 characters in one SMS, or 153 per part when split. Characters such as the euro sign and square brackets count twice. One character outside GSM-7, such as an emoji or many accented letters, switches the whole message to UCS-2 with 70 characters, or 67 per part.

Safe truncation

Cutting a string at a fixed number of UTF-16 units or bytes can split a surrogate pair, a multi-byte UTF-8 sequence or a combined emoji and produce replacement characters. The truncation here walks grapheme by grapheme and stops before the limit would be exceeded, counting the ellipsis as part of the limit.

Database columns

In MySQL, VARCHAR(255) with utf8mb4 holds 255 characters but may use up to 1,020 bytes, which matters for index length limits. PostgreSQL text has no practical limit, but byte size still affects storage and network costs.

Limits

Grapheme counting uses the browser's Unicode segmentation, which follows recent Unicode versions; very new emoji may count differently on older systems. Platform limits change, so check the current documentation of the service you target; the figures here are not official values for any platform.

Esempio svolto

The text Café crème 👩🏽‍💻 naïve résumé — 東京 has 30 characters, 33 code points, a JavaScript length of 36 and 55 UTF-8 bytes; truncated to 20 UTF-8 bytes it becomes Café crème plus an ellipsis without cutting into the emoji.

In breve

Domande frequenti

Why does JavaScript say my emoji is 2 or more long?

It counts UTF-16 units, and many emoji use two units or several code points.

How many bytes is an emoji in UTF-8?

A simple emoji is 4 bytes; combined ones with skin tones or families can be 15 to 25.

Why did my SMS become two messages?

It passed 160 GSM characters, or one character forced UCS-2 with a 70 limit.

What does safe truncation mean?

Cutting only between whole characters, so no emoji or accent is broken.

Does MySQL VARCHAR count bytes?

VARCHAR length counts characters; utf8mb4 stores up to 4 bytes per character.

Is my text uploaded?

No. All counting runs in your browser.

Completamente gratisNessun costo, nessuna registrazione
I file restano privatiTutto funziona nel tuo browser
Facile nella tua linguaDisponibile in molte lingue