Truncate, Pad and Wrap: Shaping Text to a Fixed Width
After reading this you will know how to cut text to a character limit without breaking words, pad lines so they align in a monospace column, and hard-wrap paragraphs at a fixed width, and you will understand why counting characters is trickier than it looks.
What the tool does
Three operations share one idea: they make text conform to a fixed width. Truncating cuts a long string down to a maximum length. Padding adds filler characters so every line reaches the same length. Wrapping breaks a long paragraph into lines no wider than a set number of columns.
Here is one hook. Take the line The quick brown fox jumps over the lazy dog, which is 43 characters. Truncate it to 20 characters at a word boundary and add an ellipsis, and you get The quick brown…, which is 16 characters: three whole words plus the single ellipsis character. Notice that the result is shorter than 20, not exactly 20. Word-boundary truncation gives up length to avoid cutting brown in half. That trade-off is the whole story of this tool.
When to use it, and when not
Reach for truncation when a display has hard limits: a table cell that shows 40 characters, a preview snippet, a database column capped at 255. Reach for padding when you are building fixed-width output by hand: aligning a list of names, faking a monospace table, formatting a punch-card-style record. Reach for wrapping when you paste a paragraph that arrives as one giant line and you need it broken at column 72 for an email or a commit message.
Do not use hard-wrapping for text that a screen will re-flow on its own. A web page, a word processor and a chat app already wrap soft. If you insert real line breaks at column 72 and the reader's window is narrower, the text wraps twice and looks ragged. Hard-wrap only when the destination uses a fixed width and will not wrap for you.
If your goal is to remove duplicate lines, sort them or renumber them rather than reshape their width, use Line Tools: Dedupe, Sort & Shuffle instead. This tool changes line width, not line order or line count.
Counting characters: code points, not bytes
Every operation here depends on a length, and length is ambiguous. A "character" can mean a byte, a Unicode code point, or a grapheme (what a human sees as one symbol). These three disagree.
Take the string café. If the é is stored as the single code point U+00E9, the string is 4 code points but 5 bytes in UTF-8, because é takes two bytes. If instead the é is stored as e plus a combining accent (U+0065 U+0301), the string is 5 code points and still displays as 4 symbols. An emoji like 😀 is one code point but 4 bytes in UTF-8.
This tool counts Unicode code points. That matches what most programming languages report for string length and it treats one emoji as one character. It does not count grapheme clusters, so a combining accent or a flag emoji built from two regional-indicator symbols may count as more than one. The Unicode Standard defines these levels in Annex #29 on text segmentation, which is the reference to check when the counts surprise you.
If a downstream system has a byte limit (many databases and network protocols do), code-point truncation to N can still overflow. A 20-code-point string of emoji is 80 bytes in UTF-8. Truncate for the limit that actually applies.
The rules behind each operation
Truncation to a limit L keeps the first L code points and discards the rest. With an ellipsis, the ellipsis itself must fit inside the budget, so the kept text shrinks:
Here k is the number of code points kept from the original, L is your limit, and \text{len}(\text{ellipsis}) is the length of the marker you append. The single character … (U+2026) has length 1, so truncating to 20 with an ellipsis keeps 19 original characters plus the marker, reaching 20 total. If you use three dots ... instead, that marker has length 3 and you keep only 17.
With the word-boundary option on, the cut moves left to the last space at or before position k, so the result can be shorter than L. Left padding to width W adds W - n filler characters in front of a line of length n; right padding adds them after; centre padding splits them, putting the extra one on the right when W - n is odd.
Wrapping walks a paragraph word by word and starts a new line whenever adding the next word plus one space would exceed the column limit C. A word longer than C is left intact on its own line rather than split, so URLs and long tokens survive.
Worked example with the demo data
Load the demo and you get the sentence The quick brown fox jumps over the lazy dog, 43 code points including 8 spaces. Follow each operation.
- Truncate to 20, no word boundary, ellipsis on. Budget L = 20, ellipsis length 1, so keep k = 19 code points:
The quick brown foxis exactly 19 characters, then append…forThe quick brown fox…at 20. - Truncate to 20, word boundary on. Position 19 lands on the
xoffox, mid-word. Move left to the last space, afterbrown. Kept text isThe quick brown(15 characters), plus the ellipsis givesThe quick brown…at 16. - Right-pad to 20. The truncated word-boundary result is 16 characters. Add 20 - 16 = 4 spaces on the right so it fills a 20-column cell.
- Wrap the full sentence at column 20. Fit words until the next one would pass 20.
The quick brown foxis 19, addingjumpsneeds a space and 5 more (25), so break. Line 1 isThe quick brown fox. Continue for the rest.
The wrap produces three lines: The quick brown fox (19), jumps over the lazy (19), and dog (3). No line exceeds 20, and no word is split.
The chart below shows how the kept length depends on your limit and whether the word-boundary option is on, for this exact sentence with a one-character ellipsis.
Reading the results
Three things are worth checking after any run. First, the actual length of each output line. Padding guarantees a minimum width, never a maximum: a line already longer than W is left untouched, not cut. If you need both a floor and a ceiling, truncate first, then pad. Second, whether the word-boundary retreat cost you more than you expected. A limit of 20 that lands one character into a long word can drop that whole word, leaving you well short. Third, whether wrapping preserved your paragraph breaks.
Common mistakes
The most frequent error is counting the ellipsis twice. If you want the final string to be at most 20 characters, the tool already subtracts the marker length for you; do not also shorten your limit by hand. A second mistake is padding with a multi-character filler and expecting an exact width. Padding ab to width 5 with the two-character filler xy cannot land on 5 exactly by repetition; the tool fills to the target and trims the last repeat, so you get xyxab (5), not xyxyab (6).
A third mistake is hard-wrapping text that already contains hard breaks, then wrapping again. Each pass treats existing line breaks as paragraph boundaries, so re-wrapping narrower does not undo the first wrap. If you need to change an existing wrap width, join the lines back into paragraphs first. A fourth: assuming truncation trims trailing spaces. It does not. If your kept text ends in a space, that space counts toward the length and stays before the ellipsis.
Wrapping re-flows each paragraph separately and keeps the blank lines between paragraphs intact, so a two-paragraph note stays two paragraphs after wrapping.
Try it: watch the limit reshape the result
Related tools
Shaping width is one step in a cleanup pipeline. To change letter case before or after shaping, use the Case Converter. To search and replace patterns, including collapsing runs of spaces before you pad, use Find & Replace with Regex. If your text carries accented letters that you want reduced to ASCII before a byte-sensitive truncation, run the Accent & Diacritic Remover first, since that lowers the byte-versus-code-point gap. For flipping or mirroring rather than resizing, see Reverse & Upside-down Text.
Frequently asked questions
Does the ellipsis count toward my character limit?
Yes. The tool keeps L - 1 original code points and appends the one-character ellipsis …, so the final string is exactly L when word boundary is off. Set your limit to the final width you want; do not subtract the ellipsis yourself.
Why is my truncated text shorter than the limit?
The word-boundary option moved the cut left to the last space, so no word was split. Truncating "jumps" at limit 20 retreats to after "brown", giving 16 characters. Turn the option off to cut at the exact limit.
Will an emoji count as one character or more?
Most single-code-point emoji count as one. Emoji built from several code points (a flag, or a family joined by zero-width joiners) count as more, because the tool measures code points, not grapheme clusters. For a byte limit, remember one emoji is often 4 bytes in UTF-8.
Does wrapping ever break a long word?
No. A word longer than the column limit is placed on its own line intact, so a 60-character URL survives a wrap at column 40. It will overrun the width by design, because splitting it would corrupt the link.
Can I pad and truncate at the same time to force an exact width?
Yes, in that order. Truncate to the target first, which sets the ceiling, then pad to the same width, which sets the floor. Padding alone never shortens an over-long line.