FixThatApp

Whitespace Cleaner Guide: Fix Invisible Character Problems

Updated March 19, 2026

Whitespace bugs are among the most frustrating to diagnose — they are invisible. A database query that returns no results despite looking correct, a CSV that parses wrong, a string comparison that always fails — these are often caused by trailing spaces, non-breaking spaces from copy-paste, or Windows line endings hiding inside Unix files.

Types of Whitespace Problems

1. Trailing and Leading Spaces

Spaces at the start or end of a string cause exact-match failures silently. The database field "Alice " does not match a query for "Alice". This happens when users copy-paste text, when data is imported from spreadsheets, or when CSV exports lack proper quoting.

2. Non-Breaking Spaces (U+00A0)

When you copy text from a web page, Microsoft Word, or a PDF, non-breaking spaces ( , Unicode U+00A0) often come along silently. They look identical to regular spaces visually but are a different character entirely. Standard trim() functions leave them behind, and string comparisons fail unexpectedly.

3. Windows CRLF vs Unix LF Line Endings

Windows uses \r\n (carriage return + newline) to end lines; Unix/macOS uses \n only. When a Windows file is processed on Linux, the \r character appears attached to the last word on each line. This breaks shell scripts (causing cryptic errors), breaks CSV parsing, and makes git diff show every single line as changed.

4. Tabs Mixed with Spaces

Python raises IndentationError when tabs and spaces are mixed. Even in other languages, mixing creates noise in diffs and causes code review confusion. Most style guides pick one (spaces are more common) and enforce it via linter.

5. Zero-Width Characters

Unicode includes several invisible characters: zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D), and byte order mark (U+FEFF). These sneak into text from social media, chat apps, or certain CMS platforms and cause comparison failures that are impossible to see visually.

CharacterUnicodeCommon sourceProblem
Non-breaking spaceU+00A0Web pages, Word, PDFsFails string comparisons
Zero-width spaceU+200BSocial media, chat appsInvisible, breaks matching
Byte order markU+FEFFWindows UTF-8 filesBreaks CSV and API parsing
Carriage returnU+000DWindows line endingsAppended to last token on each line
Em space / En spaceU+2003 / U+2002Word processorsWider than space, not caught by standard trim

How to Detect Hidden Whitespace

Fixing Whitespace in Code

Python

# Basic trimming
text.strip()    # removes leading and trailing whitespace
text.lstrip()   # leading only
text.rstrip()   # trailing only

# Remove non-breaking spaces and zero-width characters
import re
text = re.sub(r'[\u00A0\u200B\u200C\u200D\uFEFF]', ' ', text).strip()

# Normalise multiple spaces to single
text = re.sub(r' +', ' ', text)

# Fix Windows line endings
text = text.replace('\r\n', '\n').replace('\r', '\n')

JavaScript

// Basic trim
text.trim()

// Remove non-breaking spaces
text.replace(/\u00A0/g, ' ').trim()

// Remove zero-width characters
text.replace(/[\u200B\u200C\u200D\uFEFF]/g, '')

// Normalise all whitespace to single spaces
text.replace(/\s+/g, ' ').trim()
Excel TRIM does not remove non-breaking spaces

The =TRIM(A1) formula removes leading/trailing spaces and collapses multiple spaces, but it does not remove non-breaking spaces (U+00A0). Use =TRIM(SUBSTITUTE(A1, CHAR(160), " ")) to handle those as well.

Clean Any Text in One Click

Paste your text to remove trailing spaces, non-breaking spaces, extra blank lines, Windows line endings, and invisible Unicode characters.

Open the Whitespace Cleaner

How to Use the Whitespace Cleaner Tool

  1. Open the Whitespace Cleaner
  2. Paste your text into the input area
  3. Select the options you need: trim leading/trailing spaces, collapse multiple spaces, remove non-breaking spaces, normalise line endings, or strip zero-width characters
  4. Click Clean and copy the output

When Whitespace Is Intentional

Not all unusual whitespace is a bug. Non-breaking spaces are intentionally used to prevent line breaks between words that should stay together — "10 km", "Dr. Smith", or a number and its unit. Before cleaning, check whether the whitespace serves a purpose. The tool's selective options let you target only the whitespace types causing problems, rather than stripping everything blindly.