Text Studio · Windows 10 and 11

Remove extra spaces from text

Double spaces after full stops, stray tabs, invisible non-breaking spaces from web pages, spaces trailing at the ends of lines: Text Studio's Clean menu tidies them in one click each, on the selection or on all the text.

Updated

How to remove extra spaces

  1. 1

    Bring in the text

    Open the messy file in Text Studio with Open, or drop it onto the page. Pasted text works as well.

  2. 2

    Collapse the spaces

    Open Clean and choose Collapse extra spaces: every run of spaces, tabs and non-breaking spaces becomes a single space, and spaces at line ends go.

  3. 3

    Trim the line ends

    Choose Trim spaces at the ends of lines to remove the spaces before and after the text on each line, indents included.

  4. 4

    Finish the clean-up

    From the same menu, Straighten quotes, Remove accents, Remove HTML tags or Tabs to spaces as needed, then save or copy.

Spaces you cannot see

Text gathers spaces from everywhere it has been:

  • Double spaces after a full stop, a habit from typewriters. Chicago and APA style both ask for one.
  • Tabs from documents and spreadsheets, which look like a few spaces but are one character.
  • Non-breaking spaces from web pages, Word and PDFs. They look exactly like a space but stop a line from breaking there, and a search for a normal space does not find them.
  • Trailing spaces at the ends of lines, invisible until something compares two lines.
  • Zero-width characters, which take no room at all. Clean does not catch these; find them with Pattern on and [\u200B\u200C\u200D\uFEFF], and replace them with nothing.

Collapse extra spaces handles the first four in one go: every run of spaces, tabs and non-breaking spaces becomes a single ordinary space, and spaces left at the end of a line are removed.

Trim or collapse?

The two main choices in Clean do different jobs:

  • Trim spaces at the ends of lines removes spaces and tabs, non-breaking ones included, before and after the text on every line, and leaves the spaces between words alone. That includes indents at the start, so it would flatten code, poetry or a nested list.
  • Collapse extra spaces works anywhere in a line, but only shrinks: an indent of eight spaces becomes one, not none. It turns every tab into a space as well, which merges the columns of anything copied from a spreadsheet.

Run both, Collapse first, for clean single-spaced lines with no indents. When part of the text must keep its layout, such as a table or a code sample, select only the rest before you choose. Empty lines are a separate matter: Remove empty lines is in the Lines menu.

More in the Clean menu

  • Straighten quotes: “curly” and ‘single’ quotes become straight " and ' marks, which code, CSV files and many forms expect. The low opening quotes used in German, „ and ‚, are straightened too.
  • Remove accents: café becomes cafe and naïve becomes naive. Letters that are not an accent on a base letter, such as ø, ł and ß, stay as they are; the slug generator spells those out.
  • Remove HTML tags: deletes everything from each < to the next > and keeps the text between tags. Entities such as &amp; stay as written, and so does the code inside script and style blocks. A lone < in ordinary text can make it remove more than a tag. To turn entities back into characters, use the HTML entities tool in the Dev Toolbox.
  • Tabs to spaces: each tab becomes four spaces.

Why the spaces matter

Extra spaces are more than untidy. A name with a trailing space does not match the same name without one, so a spreadsheet lookup fails and a duplicate slips through. A non-breaking space between two words hides them from a search. Double spaces inflate a character count that has to stay under a limit, and in code, trailing whitespace shows up as noise in every change.

Clean first and the rest of the work goes better: remove duplicate lines, sort or compare the result, and lines that differed only by a space now match.

To see the effect, watch the character count in the bottom bar: it drops by exactly the number of spaces removed. Typing two spaces into Find, with Pattern off, shows how many double spaces are left anywhere in the text.

One kind of stray space survives all of this: a space before a comma or a full stop, as in “word ,”. Find a space followed by a comma, replace it with a comma alone, and do the same for full stops.

Questions, answered

Does Collapse extra spaces remove line breaks?

No, it works inside lines and leaves the line breaks where they are. To join lines, use Join broken lines in the same Clean menu.

How do I remove every space?

Press Ctrl H, turn on Pattern, find [ \t]+, leave Replace with empty and choose Replace all. Spaces and tabs go; line breaks stay.

Why are there still wide gaps after cleaning?

Some layout programs use typographic spaces, such as thin and em spaces, which Collapse does not change. With Pattern on, find [\u2000-\u200A] and replace them with a normal space.

Does it fix two spaces after a full stop?

Yes. Every run of two or more spaces becomes one, wherever it is, sentence ends included.

Can I clean a whole file?

Yes. Open a .txt, .csv, .md or .log file, clean it with nothing selected, and Save writes it back.

Is anything sent online?

Nothing. The Clean menu works inside Text Studio on your computer, so a client's export or a contract draft can be tidied with Wi-Fi switched off.

Remove extra spaces, and 16 more apps.

Download for Windows

7 days free, then from $3.99 a month for all 17 apps. Windows 10 and 11.