Overview
Introduction
Preview text, card titles, and notification snippets all need a maximum length with a visual cue that they were cut off.
This tool handles both the cutting and the suffix.
What Is String Truncator?
A truncation tool that cuts text to a maximum character length and appends a suffix only if truncation actually happened.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How String Truncator Works
The tool checks whether the input's code-point length exceeds the maximum; if so, it slices to that length and appends the suffix, otherwise it returns the input unchanged.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use String Truncator
Use it for generating preview snippets, card titles, or notification text with a consistent maximum length.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside String Slicer and Substring Extractor.
Features
Advantages
- Only adds the suffix when truncation actually occurs, avoiding a misleading '...' on already-short text.
- Operates on Unicode code points, not raw UTF-16 units.
- Checks the length before slicing, so text sitting exactly at the limit is returned untouched rather than gaining a misleading suffix.
Limitations
- Truncates at a fixed character count, not at a word boundary, so it can cut mid-word.
- Counts code points rather than display width, so a line of wide CJK characters occupies far more visual space than the same count of Latin ones.
Examples
Best Practices & Notes
Best Practices
- For word-safe truncation, manually trim to the last space before the cut point if mid-word cuts look awkward.
- Subtract the suffix's length from your budget when a hard total limit applies, since it is added on top of the maximum.
- Truncate at the point of display rather than at storage, so the full value stays available if the limit later changes.
Developer Notes
The check `chars.length <= maxLength` returns the input untouched before any slicing happens, which is what prevents the suffix from being appended to text that didn't actually need truncating.
String Truncator Use Cases
- Generating a preview snippet with a consistent max length
- Shortening a title for a card or list view
- Truncating text for a notification with limited space
Common Mistakes
- Expecting truncation to respect word boundaries; it cuts at an exact character count.
- Truncating text containing an emoji built from several code points, which can cut the sequence apart and leave a fragment behind.
Tips
- Set the max length to account for the suffix's own length if you need a strict total character budget.
- Setting the suffix to an empty string gives a plain hard cut, which is usually what fixed-width formats actually need.