Skip to main content

Text: Trim

Strip whitespace from the start, end, or both sides of a string. Inner whitespace is preserved — use Text::RegexpCapture or Text::Replace if you need to collapse runs of whitespace.

Example
Mode: Both → " hello " → "hello"
Mode: Start → " hello " → "hello "
Mode: End → " hello " → " hello"

Parameters

Trim mode

Which side(s) to trim:

  • Both (default) — trim leading and trailing whitespace.
  • Start — trim leading only.
  • End — trim trailing only.

Input

Stringrequired
Text to trim.

Output

String
The trimmed text.