ETEvoraTools
Text Formatting

Trim Whitespace

Trim Whitespace normalizes CRLF to LF, applies trim() to each line, rejoins with LF, and trims the entire result. It removes indentation and trailing spaces from nonempty lines plus leading/trailing blank lines, but preserves blank lines inside the remaining text. Tabs and other Unicode whitespace recognized by trim are removed at line edges.

Runs locally — files stay on your device
Quick answer

Does this preserve indentation?

No.

Line-edge trimming can change structured text

Indentation can be meaningful in code, Markdown, YAML, poetry, and plain-text layouts; removing it is not always cosmetic.

How it works

Every line receives String.trim; the joined string receives trim again.

Key concepts

Each line trimmed

Leading indentation disappears everywhere.

Internal blanks remain

Only outer blank lines are removed by final trim.

When to use it

  • Clean accidental spaces around list lines.
  • Remove outer blank space from plain text.
  • Normalize unindented line content.

When not to use it

  • Do not trim indentation-sensitive code/YAML.
  • Do not expect internal repeated spaces removed.
  • Do not use when trailing spaces encode Markdown line breaks.

Worked examples

Edges

Input
a \n b
Expected output
a\nb

Both line edges trim.

Internal spaces

Input
a b
Expected output
a b

Middle stays.

Blank paragraph

Input
a\n\nb
Expected output
a\n\nb

Internal blank remains.

Common mistakes

Trimming code

Indentation semantics break. Correction: Use a syntax-aware formatter.

Markdown hard breaks

Trailing spaces can be meaningful. Correction: Review Markdown before trimming.

Expecting collapse

Internal spaces remain. Correction: Use whitespace normalization if desired.

Best practices

  • Use on non-indentation-sensitive text.
  • Keep source.
  • Inspect Markdown/code boundaries.

Related operations and differences

Remove Extra Spaces

Choose Remove Extra Spaces when you need to collapse repeated spaces while preserving lines.; use Trim Whitespace specifically for trim whitespace.

Tabs to Spaces

Choose Tabs to Spaces when you need to replace tab characters with a chosen number of spaces.; use Trim Whitespace specifically for trim whitespace.

Add Prefix to Every Line

Choose Add Prefix to Every Line when you need to add the same prefix before every line.; use Trim Whitespace specifically for trim whitespace.

Add Suffix to Every Line

Choose Add Suffix to Every Line when you need to add the same suffix after every line.; use Trim Whitespace specifically for trim whitespace.

Capitalize Every Word

Choose Capitalize Every Word when you need to capitalize the first character of every word.; use Trim Whitespace specifically for trim whitespace.

Character Counter

Choose Character Counter when you need to count Unicode characters in text.; use Trim Whitespace specifically for trim whitespace.

Limitations and privacy

  • Per-line trim plus global trim only; no indentation preservation option, trailing-only mode, whitespace visualization, format awareness, or report.

Text is transformed locally in this browser and is not uploaded by the tool.

Frequently asked questions

Are internal spaces collapsed?

No.

Are blank lines inside text removed?

No.

Are leading blank lines removed?

Yes.

Can code indentation break?

Yes.

References