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.
Compatibility
▾| Excel | ✔ |
| Gnumeric | ✔ |
| Google_sheets | ✔ |
| Libreoffice | ✔ |
| Numbers | ✔ |
| Onlyoffice | ✔ |
| Openoffice | ✔ |
| Wps | ✔ |
| Zoho | ✔ |
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
TRIM is your whitespace‑normalizer — perfect for cleaning messy text, preparing data for parsing, and ensuring consistent, predictable string behavior.
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.