text-trimmer
A text trimmer removes leading and trailing whitespace β spaces, tabs, and newlines β from a text block as a whole or from every line individually, optionally stripping completely empty lines. The ZTools Text Trimmer offers four common modes (trim start only, trim end only, trim both, trim per-line), preserves intentional internal whitespace, can collapse empty lines into single empty separators, and works on any size paste β fixing the invisible whitespace bugs that break form validation, cause "Apple" and "Apple " to count as different items, and pollute log analysis.
Use casesβ
Cleaning copy-pasted user input before submissionβ
Forms reject "user@example.com " (trailing space) as an invalid email. Trim before submitting and save the round-trip.
Pre-processing a list before deduplicationβ
"Apple\n" and "Apple \n" deduplicate as different items. Trim per-line first, then deduplicate β the right order matters.
Removing indentation from a code pasteβ
Paste indented code, trim per-line to get unindented output. Useful when copying snippets from articles where leading whitespace breaks Python indentation.
Cleaning translation files and config exportsβ
Translators sometimes leave trailing spaces around punctuation. A per-line trim normalizes the file before checking it into version control.
How it worksβ
- Paste your text β Any size. Whitespace inside lines is preserved unless you enable inner-collapse mode.
- Pick the trim mode β Trim whole text (only the very start and very end of the paste), trim each line (every line's leading + trailing whitespace), trim start only, trim end only.
- Optional: handle empty lines β Keep empty lines as-is, collapse runs of empty lines to one, or remove all empty lines entirely.
- Copy the output β Side-by-side preview shows before and after. One-click copy or download.
Examplesβ
Input: " hello \n world \n"
Output: "hello\nworld" (per-line trim, empty lines removed)
Input: "Apple \nBanana\n Cherry"
Output: "Apple\nBanana\nCherry" (per-line trim)
Input: "\n\n\nReal content\n\n"
Output: "Real content" (whole-text trim)
Frequently asked questionsβ
What's the difference between "trim text" and "trim lines"?
"Trim text" removes whitespace only at the very start and end of the entire paste β useful when removing leading/trailing newlines from a copied block. "Trim lines" trims every individual line β useful for cleaning user-input lists.
Does trimming remove tabs and newlines too?
Yes β by default, trim removes any Unicode whitespace: space, tab, newline (LF), carriage return (CR), zero-width space, non-breaking space. You can configure which characters count as "whitespace".
Will it touch whitespace inside lines?
No β trim only removes whitespace at the start or end. Internal multi-space ("hello world") stays as-is. To collapse internal whitespace, use the Multiple Whitespace Remover tool.
Why are some "spaces" not removed?
They might be non-breaking spaces (U+00A0) or zero-width characters (U+200B). The default trim handles Unicode whitespace, but check the option panel if anything looks left over.
Should I trim before or after deduplication?
Always before. Trim normalizes the comparison so "Apple " and "Apple" are seen as identical when deduplicating.
Tipsβ
- Always trim user input before validating, comparing, or storing β invisible whitespace bugs are the #1 form-validation issue.
- When importing CSVs, trim each cell before parsing to handle the "Excel exported with trailing spaces" problem.
- For source code, trim trailing whitespace per line (most editors do this on save) but never leading β that breaks indentation.
- Combine with the "remove empty lines" option for clean list outputs ready to feed into other tools.
Try it nowβ
The full text-trimmer runs in your browser at https://ztools.zaions.com/text-trimmer β no signup, no upload, no data leaves your device.
Last updated: 2026-05-05 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub