TToolbox
␣

Whitespace Cleaner

Strip extra spaces, blank lines and invisibles

About this tool

Whitespace characters are the invisible saboteurs of digital text processing. Beyond standard spaces and newlines, text copied from PDFs, Word docs, and web pages frequently harbors non-breaking spaces (U+00A0), full-width CJK spaces (U+3000), and completely invisible zero-width ghost characters (U+200B, U+FEFF). These cause mysterious compilation failures, database query misses, and broken passwords. This tool detects, visualizes, and purges all redundant and invisible whitespace locally.

How to Use This Tool (Step-by-Step)

1

Paste Problematic Text

Paste code snippets throwing mysterious syntax errors or text copied from PDF documents into the workspace.

2

Select Cleaning Rules

Configure cleaning toggles: Trim line edges, collapse multiple consecutive spaces, remove blank lines, and purge invisible zero-width characters.

3

Inspect Metrics and Copy Clean Text

Review metrics highlighting purged invisible bytes and collapsed spaces, then copy the normalized clean text with one click.

Zero-Width Ghost Character Purge

Rigorously detects and strips zero-width spaces (U+200B), zero-width non-breaking spaces (U+FEFF), and invisible watermark tokens.

Full-Width to Half-Width Normalization

Converts accidental CJK full-width spaces (`\u3000`) into standard ASCII spaces and collapses multiple blank lines cleanly.

100% Client-Side Air-Gapped

Text sanitization runs entirely within local browser memory. Internal code snippets and configuration variables are never uploaded.

Zero-Width Watermarking & Text Safety Tips

  • •Defeat zero-width text watermarking: Some enterprise intranets insert invisible zero-width sequences to track copy-pasters. Cleaning text strips all hidden watermarks.
  • •` ` (U+00A0) is NOT standard ASCII space 32: `split(' ')` fails on non-breaking spaces copied from websites. Always normalize U+00A0 to standard space.
  • •Do not strip leading spaces in code: Cleaning leading indentation destroys Python scripts and Markdown lists. Only strip trailing line whitespace on code files.

Code & Transformation Examples

Common Invisible Unicode Whitespace Benchmark

Character & Unicode Code Point
• 零宽空格 (Zero-Width Space)       : U+200B (占用 0 像素物理宽度,完全隐形)
• 零宽无断空格 (BOM / ZWNBSP)       : U+FEFF (常见于文件开头字节标记)
• 不换行空格 (Non-breaking Space)   : U+00A0 (  网页常见,非普通空格)
• 全角空格 (Ideographic Space)      : U+3000 (中文全角大空格,占 1 个汉字宽)
Troubleshooting Scenario
在终端执行命令或代码编译时,明明看着是英文字符却报错 "SyntaxError: Invalid or unexpected token",99% 的原因就是代码里混入了上述看不见的零宽字符!

* Two strings appearing identical to human eyes evaluate to `false` in code when contaminated by U+200B.

JavaScript Zero-Width Character Stripping Snippet

Zero-Width Cleaning Regex
function removeInvisibleChars(str) {
  // 匹配常见的零宽与格式控制字符
  return str.replace(/[\u200B-\u200D\uFEFF\u200E\u200F\u00A0]/g, '');
}
Comprehensive Whitespace Trimmer
function cleanWhitespace(text) {
  return text
    .replace(/\u3000/g, ' ') // 全角空格转半角
    .replace(/[\u200B-\u200D\uFEFF]/g, '') // 删零宽字符
    .replace(/[^\S\r\n]+/g, ' ') // 连续横向空格折叠为单空格
    .replace(/^ +| +$/gm, '') // 去除每行首尾空格
    .replace(/\n{3,}/g, '\n\n'); // 连续空行折叠
}

* Running this sanitizer on user form inputs prevents hundreds of mysterious registration bugs.

Frequently Asked Questions

Q: Why does pasted code run in editors but fail in terminals?

A: Web documentation often uses non-breaking spaces (` `). Terminal shells like Bash reject U+00A0 as invalid syntax. Cleaning text resolves it immediately.

Q: What is a Zero-Width Joiner (ZWJ, U+200D)?

A: Zero-Width Joiners link separate characters into single glyphs, such as composite emojis (👩‍⚕️). The cleaner preserves ZWJ within valid Emoji sequences.

Q: Can this cleaner handle novel-length manuscripts?

A: Powered by compiled V8 native regexes, novel-length manuscripts with hundreds of thousands of words sanitize in dozens of milliseconds.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/