TRIM
The TRIM function returns the given string with any leading and trailing blacks that are removed, or the given string with any leading and trailing specified characters removed.
The type of the function is alphanumeric, DBCS, or national depending on the class of its argument.
- argument-1
- Must be a nonnumeric literal or data item of class alphabetic, alphanumeric, DBCS, or national. Argument-1 identifies the source string for the trim.
- argument-2
- If specified, it must be a nonnumeric literal or data item of the same class as argument-1. It specifies the characters to trim off. If not specified, the trim character defaults to blank.
The length of the returned string depends on the content and the class of argument-1. It is the length of the returned string in number of character positions. If argument-1 is a DBCS or national data item, the length is in DBCS or national character positions.
Returned values
The order of the characters in the argument-2 parameter does not affect the outcome of the operation. The characters are a list of single characters. For example, FUNCTION TRIML(fld, "abc") returns the substring of fld that begins with any character that is not 'a', 'b', or 'c'. If fld contains "caxyz", FUNCTION TRIM(fld, "abc") returns "xyz". Characters can appear twice in the second parameter with no error. For example, FUNCTION TRIM(fld, "aba") is valid. This means the same as FUNCTION TRIM(fld, "ab").
If the second parameter of FUNCTION TRIM, TRIML, or TRIMR is specified, blanks are not trimmed unless a blank appears as part of argument-2. TRIM, TRIML, and TRIMR functions are not sensitive to mixed SBCS/DBCS strings. Both argument-1 and argument-2 are treated as SBCS if their class is alphanumeric.
Examples:
FUNCTION TRIM("xxxABxCxxx", "x") // returns 'ABxC'
FUNCTION TRIMR(">>>>ABC<<<<<", "<>") // returns '>>>>ABC'
MOVE "xyz" TO tc.
FUNCTION TRIML("xxyyzzyyzzABCxyzyxzxy", tc) // returns 'ABCxyzyxzxy'
