Tabular IQ
Back to Function Index

TRIM()

Overview

TRIM() removes specified characters from both the left and right sides of a string. The function iteratively removes characters that match the provided list from both ends until no more matches are found. If no list is provided, TRIM() removes spaces by default. This function is similar to LTRIM() and RTRIM(), which remove characters from only one side of the string.

Function Format

TRIM(string [, list])

Return Value

TRIM() returns a character string

Examples


// Default space removal
TRIM(" APPLES ") = "APPLES"

// Removing specific characters
TRIM("APPLES", "AS") = "PPLE"
TRIM("APPLES", "APS") = "LE"
TRIM("APPLES", "E") = "APPLES"
TRIM("APPLES", "PS") = "APPLE"

// Order of characters in list doesn't matter
TRIM("APPLES", "APS") = "LE"
TRIM("APPLES", "PSA") = "LE"

// Complex examples
TRIM("ABRACADABRA", "ABR") = "CAD"
TRIM("ABRACADABRA", "ARBD") = "C"

// Additional examples
TRIM("  Hello  ", "") = "Hello"     // Default space removal
TRIM("***Text***", "*") = "Text"    // Removing special characters
TRIM("123ABC123", "123") = "ABC"    // Removing numbers

Notes

  • Important behaviors:
    • Removes characters from both ends
    • Process repeats until no matches found
    • Order of characters in list doesn't matter
    • Default behavior removes spaces
    • No effect on characters in middle of string
  • Common use cases include:
    • Removing whitespace
    • Cleaning data
    • String normalization
    • Text formatting
    • Data preprocessing
  • The function is useful for:
    • Data cleaning
    • Input validation
    • String standardization
    • Text processing
  • Important considerations:
    • Process is iterative from both ends
    • Characters are removed only from ends
    • Empty list defaults to space removal
    • No effect if no matches found

See Also