C0/C1 control characters: what lives between U+0000 and U+009F

Topic illustration for the article: C0/C1 control characters: what lives between U+0000 and U+009F
Practical illustration for this guide

An import log once gave me a record that looked empty yet still occupied a row. It contained U+0000, not a space. That is why “invisible character” is too broad here: the C0/C1 ranges contain both useful separators and genuine debris.

Inspect a control-character sample

The ranges are a historical toolbox

C0 covers U+0000–U+001F plus DELETE U+007F; C1 covers U+0080–U+009F. Unicode preserves these positions for compatibility but does not give every control the same modern purpose. TAB, LF and CR are routine. BEL, ESC and NUL inside a form field usually deserve investigation.

A code point is not a raw byte

U+0085 is NEXT LINE, while byte 0x85 in a legacy single-byte encoding may represent something else. Establish whether the input has already been decoded as Unicode. Mojibake is an encoding problem and should be repaired before a control-character scan can be trusted.

Why a range-wide deletion damages data

Removing all C0 controls also removes tabs and line endings. A CSV can lose structure, a log can collapse into one line and source code can change. Start with an allow-list for the particular field: LF may be valid in a comment but invalid in a product identifier.

Trace the character back to its source

Record the position, code point and neighbours, then test one route at a time: clipboard, export, API or database. NUL after every visible character often signals UTF-16 read as an incompatible format. ESC may come from terminal output; U+0085 may survive an older office export.

A regular expression is only a detector

JavaScript Unicode property escapes can report General_Category=Control, but they do not understand intent. Highlight first, then preserve TAB, LF and CR where needed. For user documents, show a preview and a replacement log instead of silently rewriting the only copy.

Define success in the destination

A zero counter is not the goal. The import must work, rows must remain rows and meaning must survive. Keep the failing sample as a regression test. If every new export recreates the same control, fix the source pipeline instead of repeatedly cleaning its output.

Reproducible example

The string below contains BEL U+0007 between A and B. It occupies no column but remains part of equality and length checks. Report matches first; any production removal should use an explicit, reviewed list.

const value = "A\u0007B\nC";
[...value].map((ch, i) => ({ i, cp: "U+" + ch.codePointAt(0).toString(16).toUpperCase() }));
const report = value.match(/\p{Cc}/gu);

Four checks before changing data

  1. Preserve the source file and its declared encoding.
  2. Separate required TAB, LF and CR from unexpected controls.
  3. Change a copy and repeat the operation that originally failed.
  4. Compare row count, field count and untouched content.

Open the cleaner

Sources and specifications

Related guides

Mykola prepared this guide from reproducible samples and primary specifications. The receiving format, not a generic cleaner, defines the final rule.