TRIM

TRIM removes the trailing, leading, and consecutive spaces in a string.

Function category: Text

Syntax

TRIM(arg1)

Arguments

Description

arg1

A string.

Examples

If we receive the following data that is padded by spaces:

{
"data":{
"product_reviews": {
"review_1": " Product was acceptable, a 6/10.",
"review_2": " Product was ok, needs improving. "
}
}

Example 1: Trim initial space from strings

If we want to strip the initial space from the first review, use the following function.

# Remove initial space
TRIM(data.product_review.review_1)
# returns "Product was acceptable, a 6/10."

Example 2: Reduce multiple spaces to single spaces

We can also reduce any consecutive spaces to a single space. To remove any additional spaces in the second review, use the following function.

# Remove consecutive spaces
TRIM(data.product_review.review_2)
# Returns "Product was ok, needs improving."