Complete Guide to Text Conversion, Formatting & Cleaning

A deep dive into text transformation: case conversion, whitespace cleaning, encoding and formatting — with examples and use cases.

Everything you need to know about converting, formatting and cleaning text — cases, whitespace, encoding and more.

Key points from this guide

  • Work in a fixed order: strip formatting first, clean whitespace and line breaks second, then convert case last — converting before cleaning bakes stray spaces into the result.
  • Text pasted from a PDF carries a hard line break on every line; removing breaks before removing extra spaces avoids double spacing where lines join.
  • Text pasted from Word carries non-breaking spaces, smart quotes and hidden HTML when it lands in a rich editor — paste as plain text first when the destination is a CMS.
  • Case conversion is lossy in one direction only: you can always go to lowercase, but you cannot recover the original capitals afterwards.
  • For repeatable work, keep the same pipeline every time so two people cleaning the same export get the same output.

Frequently asked questions

What order should text cleaning steps run in?

Remove HTML and formatting, then line breaks, then extra spaces and empty lines, then de-duplicate, and only then convert case. Each step assumes the previous one has run.

Why does cleaned text still look wrong in my CMS?

The characters are clean but the paste carried inline styling. Paste as plain text (Ctrl+Shift+V) or run the text through the HTML tag remover before pasting.