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.
TRIM(string [, list])
TRIM() returns a character string
// 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