Transformation Language Reference > Functions > RTRIM
  

RTRIM

Removes blanks or characters from the end of a string.
If you do not specify a trim_set parameter in the expression:
If you use RTRIM to remove characters from a string, RTRIM compares the trim_set to each character in the string argument, character-by-character, starting with the right side of the string. If the character in the string matches any character in the trim_set, RTRIM removes it. RTRIM continues comparing and removing characters until it fails to find a matching character in the trim_set. It returns the string without the matching characters.

Syntax

RTRIM( string [, trim_set] )
The following table describes the arguments for this command:
Argument
Required/
Optional
Description
string
Required
Any string value. Passes the values you want to trim. You can enter any valid transformation expression. Use operators to perform comparisons or concatenate strings before removing blanks from the end of a string.
trim_set
Optional
Any string value. Passes the characters you want to remove from the end of the string. You can also enter a text literal. However, you must enclose the characters you want to remove from the end of the string within single quotation marks, for example, 'abc'. If you omit the second string, the function removes blanks from the end of the first string.
RTRIM is case sensitive.

Return Value

String. The string values with the specified characters in the trim_set argument removed.
NULL if a value passed to the function is NULL.

Example

The following expression removes the characters ‘re’ from the strings in the LAST_NAME port:
RTRIM( LAST_NAME, 're')
LAST_NAME
RETURN VALUE
Nelson
Nelson
Page
Pag
Osborne
Osborn
NULL
NULL
Sawyer
Sawy
H. Bender
H. Bend
Steadman
Steadman
RTRIM removes ‘e’ from Page even though ‘r’ is the first character in the trim_set. This is because RTRIM searches, character-by-character, for the set of characters you specify in the trim_set argument. If the last character in the string matches the first character in the trim_set, RTRIM removes it. If, however, the last character in the string does not match, RTRIM compares the second character in the trim_set. If the second from last character in the string matches the second character in the trim_set, RTRIM removes it, and so on. When the character in the string fails to match the trim_set, RTRIM returns the string and evaluates the next row.
In the last example, the last character in Nelson does not match any character in the trim_set argument, so RTRIM returns the string 'Nelson' and evaluates the next row.

Tips for RTRIM

Use RTRIM and LTRIM with || or CONCAT to remove leading and trailing blanks after you concatenate two strings.
You can also remove multiple sets of characters by nesting RTRIM. For example, if you want to remove trailing blanks and the character ‘t’ from the end of each string in a column of names, you might create an expression similar to the following:
RTRIM( RTRIM( NAMES ), 't' )