TRIM Function (LibreOffice Calc)
The TRIM function in LibreOffice Calc removes extra spaces from text, leaving only single spaces between words. It is essential for data cleaning, normalization, and preparing text for parsing.
Verification status: Consult the documentation, examples and any stated test scope below. How formula examples are checked
Availability and version history
- Introduced: Documented by LibreOffice 26.8.1.1; original introduction not established.
- Availability: Supported in LibreOffice 26.8.1.1, verified against its function registry. This identifies a supported release, not a final working version.
- Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
- Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.
What the TRIM Function Does
- Removes leading spaces
- Removes trailing spaces
- Reduces multiple internal spaces to a single space
- Normalizes text for parsing and comparison
- Works with text, numbers (converted to text), and formulas
It is designed to be simple, reliable, and essential for data cleaning.
Syntax
TRIM(text)
Arguments
- text:
The text string to clean.
Basic Examples
Remove leading/trailing spaces
=TRIM(" Hello ")
Returns "Hello".
Reduce multiple spaces between words
=TRIM("A B C")
Returns "A B C".
Clean a cell value
=TRIM(A1)
Clean a number stored as text
=TRIM(" 42 ")
Returns "42" (still text).
Advanced Examples
Prepare text for FIND/SEARCH
=FIND(" "; TRIM(A1))
Normalize imported CSV data
=TRIM(A1)
Clean text before concatenation
=CONCAT(TRIM(A1); " "; TRIM(B1))
Clean text before comparison
=IF(TRIM(A1)=TRIM(B1); "Match"; "No match")
Clean text before VALUE conversion
=VALUE(TRIM(A1))
Clean text before splitting
=LEFT(TRIM(A1); FIND(" "; TRIM(A1)) - 1)
Clean text before SUBSTITUTE
=SUBSTITUTE(TRIM(A1); " "; "_")
Clean text before TEXTJOIN
=TEXTJOIN(" "; TRUE; TRIM(A1:A5))
Clean text with non-breaking spaces (requires SUBSTITUTE)
=TRIM(SUBSTITUTE(A1; CHAR(160); " "))
Edge Cases and Behavior Details
TRIM removes:
- Leading spaces
- Trailing spaces
- Multiple internal spaces
TRIM does not remove:
- Tabs (CHAR(9))
- Non-breaking spaces (CHAR(160))
- Line breaks
- Unicode whitespace beyond ASCII 32
Use CLEAN or SUBSTITUTE for those.
TRIM of an empty string returns empty string
=TRIM("") → ""
TRIM of a blank cell returns empty string
=TRIM(A1) → ""
TRIM of a number converts it to text
=TRIM(123) → "123"
TRIM of an error propagates the error
=TRIM(#N/A) → #N/A
TRIM does not collapse tabs or other whitespace
Use:
=TRIM(SUBSTITUTE(A1; CHAR(9); " "))
Common Errors and Fixes
TRIM does not remove all spaces
Cause:
- Non-breaking spaces
- Tabs
- Unicode whitespace
Fix:
Use SUBSTITUTE(A1; CHAR(160); " “) or CLEAN(A1).
TRIM returns unexpected spacing
Cause:
- Multiple spaces replaced by one
- User expected exact spacing preserved
TRIM converts numbers to text
Cause:
- TRIM always returns text
- Use VALUE(TRIM(A1)) to restore numeric type
Best Practices
- Use TRIM before parsing text with FIND/SEARCH
- Use TRIM before concatenation to avoid double spaces
- Use TRIM before comparison to normalize input
- Combine TRIM with CLEAN for full whitespace cleanup
- Use SUBSTITUTE to remove non-breaking spaces
- Use TRIM on imported or pasted data
Related Patterns and Alternatives
- Use CLEAN to remove non-printable characters
- Use SUBSTITUTE to remove specific characters
- Use LEFT, RIGHT, MID for extraction
- Use VALUE to convert cleaned text to numbers
- Use TEXTJOIN and CONCAT for assembly
By mastering TRIM and its companion functions, you can build clean, reliable, and fully normalized text‑processing workflows in LibreOffice Calc.
Reproducible example (tested in LibreOffice Calc)
This standalone example was calculated in LibreOffice Calc 25.2.3.2 and matched the expected value. It is a practical cross-check of one usage, not proof that every example elsewhere on this page is correct.
=TRIM(" one two ")
Expected result: one two.
Remove leading/trailing spaces and reduce repeated internal spaces.
If the result differs, check the referenced cells, argument separators and number formatting. For more information, consult the LibreOffice Calc official help.