Remove leading and trailing whitespace from text

Remove ECMAScript whitespace or a chosen character set from document or line edges.

freeworks offlinenothing uploaded
ToolText Trimmer
Input
Output

How it works

Whitespace mode applies trim, trimStart, or trimEnd to the complete string or each CRLF/LF row. Custom mode builds a set from the entered UTF-16 units and removes matching units only while they occur at the selected edges.

  • Both outer edges are selected first because that matches String.prototype.trim.
  • Per-line and custom-character modes are opt-in because they can remove meaningful indentation or punctuation.

Worked example

Trim whitespace from lines
Remove leading and trailing spaces from each line
Input
											  hello world  
  foo bar  
										
Output
												hello world  
  foo bar
											

When to use this

Copied API tokens lose accidental outer newlines, exported columns shed surrounding spaces, and fixed marker characters are removed from pasted labels.

Edge cases

  • Whole-document mode leaves spaces at the beginning of interior lines because they are not document edges.
  • Per-line mode strips indentation and rejoins Windows CRLF rows with LF.
  • Custom characters ab trim any run of a or b at an edge, not one literal ab substring.

References