Whitespace Cleaner
| Input | Output | Rule |
|---|---|---|
··padded line·· | padded line | Edge trim (default on) strips line-edge blanks, tabs, NBSP and BOM |
a····b | a b | Collapse (default on) squeezes runs of 2+ plain spaces to one |
word word | word word | Interior tabs survive - collapse matches plain spaces only |
(blank line) | kept | Blank lines stay by default; the third toggle drops them |
cafe corner | cafe corner | Interior NBSP is data, not dirt - it survives by design |
Bottom line: whitespace is invisible but load-bearing - a trailing space makes two 'identical' lines differ in any exact comparison, a full-width space from CJK input passes every visual check while breaking keyword matching, and doubled sentence spaces survive three rounds of proofreading. This tool removes what the eye cannot rank.
Copied-from-PDF text, CSV exports and pasted emails all carry the same disease: stray leading spaces, doubled spaces and random blank lines. This cleaner trims every line, squeezes space runs down to a single space, and optionally drops blank lines — with a live count of what was removed.
It pairs with the duplicate remover and line sorter as the list-cleaning toolkit: dedupe, sort, strip whitespace, done. All processing is local JavaScript — nothing you paste leaves your browser.
How to use
- Paste the messy text into the input box.
- Toggle trims on or off — trim line edges, collapse inner space runs, drop blank lines.
- Read the removal stats, then copy the cleaned result.
Frequently asked questions
What is whitespace?
Any invisible spacing character: regular spaces, tabs, and the line breaks themselves. Cleaner text with tidy whitespace compiles better, sorts better, and pastes into spreadsheets without phantom columns.
Does it remove spaces inside sentences?
Only the extra ones: 'hello world' becomes 'hello world' with one space kept, when collapse mode is on. You choose which cleanups run.
Is my text uploaded anywhere?
No — cleaning is pure JavaScript in your browser. Disconnect from the internet and it still works; nothing is logged anywhere.
Can it clean tabs too?
Yes — tab characters are treated as whitespace and handled by the trims and collapsing, alongside regular spaces.
Will cleaning whitespace break my code or CSV?
It can - which is why this is a text tool, not a code formatter. Code indentation is meaningful whitespace (Python would stop compiling), and CSV parsers treat quoted fields differently from bare ones. Run it on prose, pasted email text, keyword lists and copied articles; keep it away from source files, data formats with significant spacing, and anything where alignment carries meaning. When in doubt, clean a copy first.
Why do two identical-looking strings compare unequal?
Invisible characters. A zero-width space (U+200B) copied from a PDF or rich-text editor sits inside one string but not the other; a non-breaking space (U+00A0) looks exactly like a plain space but has a different code; a file may begin with the invisible byte-order mark (U+FEFF). None of them render, so the strings print identically and still fail equality checks, regex matches, hash comparisons and database joins. This tool trims those characters at line edges (the ECMAScript whitespace definition includes them), but interior invisible characters are content by design - paste a suspect string into an inspector that lists code points, and the difference becomes visible in one screen.