Yueseryueser.com

← All guides

Collapse Spaces: Cleaning Gaps from Pasted Text

Text copied from a web page, a PDF, or a spreadsheet often arrives with runs of spaces inside it. Collapsing them changes no words, only the gaps.

Open the tool:Collapse Spaces

When you actually need it

Web page text is the usual source: multiple spaces were inserted in the markup for alignment and survive the copy. PDF extraction leaves irregular gaps between words, so a paragraph looks loose and the line length jumps around.

Columns copied from a spreadsheet, chat logs, and OCR output carry the same clutter. Collapsing it before pasting into an email, a form, or a document makes the layout predictable and stops lookups from failing over a difference in space count.

What it changes and what it ignores

Runs of spaces and tabs become a single space, and nothing else is touched. Leading indentation is compressed to one space rather than removed, so a small gap remains on the left; run a trim afterwards if you want a hard left edge.

Several kinds of whitespace are left alone. Line breaks survive, so the line structure is unchanged. The ideographic space U+3000 is not a half-width space and is not collapsed, which is why wide gaps in Chinese text look untouched, and the non-breaking space U+00A0 stays as well.

Alternatives and when to avoid it

Do not run it on code. Indentation compressed to one space breaks Python immediately and ruins readability elsewhere, and anything aligned with spaces loses its layout. Two trailing spaces in Markdown mean a hard line break, which also disappears.

To remove only trailing spaces, a regex replace in the editor is more precise. To clear full-width spaces too, convert them to half-width first and then collapse. When paragraph structure matters, delete empty lines and collapse spaces as separate steps.

FAQ

Why did the gaps in my Chinese text not change?

Those gaps are usually not half-width spaces but the ideographic space U+3000 or a non-breaking space U+00A0, and this tool only merges ordinary spaces and tabs. Convert full-width to half-width first, then collapse.

Why is there still one space at the start of each line?

Because runs are compressed to a single space rather than deleted, so the leading space survives. Run the trim tool afterwards if you want a flush left edge.

Are line breaks removed as well?

No. The operation applies to spaces and tabs only, so line breaks and paragraph structure stay as they were. To merge lines, use the convert-to-one-line tool instead.

Related tool:Collapse Spaces