TRIM
Removes leading/trailing whitespace and collapses internal runs to single spaces.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=TRIM(text)
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
text | any | Required | — |
Return type
Can return text.
Remarks
- Leading and trailing whitespace is removed.
- Consecutive whitespace inside the text is collapsed to one ASCII space.
- Non-text inputs are coerced to text before trimming.
- Errors are propagated unchanged.
Examples
Remove leading and trailing spaces and collapse interior space runs.
Formula =TRIM(" East Team ")
Expected result East Team
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Trim padding around a single word.
Formula =TRIM(" East ")
Expected result East
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A string consisting entirely of spaces becomes empty.
Formula =TRIM(" ")
Expected result ""
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
An input error propagates before trimming.
Formula =TRIM(1/0)
Expected result #DIV/0!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Normalize spacing
Formula =TRIM(" alpha beta ")
Expected result alpha beta
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Already clean text
Formula =TRIM("report")
Expected result report
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
What whitespace does TRIM normalize?
It trims edges and collapses internal whitespace runs to single spaces.