How to Clean Up Messy Text With Extra Spaces
Text pasted from a PDF, an email or a web page arrives carrying whitespace nobody put there deliberately. The Whitespace Trimmer strips the extra spaces and blank lines in one pass.
Where the mess comes from
PDFs are the worst offender, because a PDF stores the position of each piece of text rather than a flowing paragraph. Copying from one produces line breaks at the end of every visual line, double spaces where the original was justified, and sometimes a space between every letter of a heading.
Email adds its own: quoted-line prefixes, hard line breaks at seventy-odd characters, and blank lines between every paragraph after a few rounds of replies.
Web pages bring non-breaking spaces, which look exactly like ordinary spaces and are a different character entirely. That is the one that causes the strangest bugs, because a search for a normal space does not find it.
Spreadsheets leave trailing spaces in cells, invisible and persistent, usually from manual data entry.
Which ones actually matter
A double space in prose is cosmetic - typographic convention, and nobody will notice either way. The ones that cause real problems are trailing and leading whitespace, because they are invisible and they break comparisons.
A trailing space means two identical-looking entries are different strings. That defeats de-duplication, so the Duplicate Line Remover leaves both copies. It breaks lookups, so a row that should match does not. It breaks sorting, since a leading space usually sorts before every letter. And it breaks validation, which is why an email address with a trailing space is rejected by a form that gives no useful reason.
Clean the whitespace before doing anything else with the text. Everything downstream depends on it.
Blank lines
A stray blank line between paragraphs is harmless in a document and not harmless in data, where it becomes an empty record. Converting a list with blank lines in it produces entries that are empty strings, and those then have to be filtered somewhere else.
Collapsing runs of blank lines to one, and removing them entirely from a list, are both worth doing as a first step.
Common questions
Will it remove the line breaks I want to keep?
Trimming removes space at the ends of lines and collapses repeated blanks; it does not join your paragraphs together.
What about non-breaking spaces?
They are a different character from a space, which is exactly why they survive manual cleanup. A trimmer that handles them saves a long hunt.
Is my text uploaded?
No. It is cleaned in your browser.
Should I use one space or two after a full stop?
One, in anything set in a proportional typeface. The two-space habit comes from typewriters, where every character had the same width.
Can I keep deliberate indentation?
Trimming is aimed at accidental whitespace, so check the result if the indentation is meaningful - as it is in code or poetry.
Got text that will not behave?