TRIM/TRIMB/TRIMF Functions

Removes blank spaces or another specified character from a string.

Syntax

TRIM(string{, removeChar{, type}})

TRIMB(string)

TRIMF(string)

Syntax Elements

string An expression that evaluates to the string to be trimmed.

removeChar The character to be removed from the string. The default, if the removeChar parameter is omitted, is a space.

  • Only the first character in removeChar is significant; subsequent characters are ignored.

  • If removeChar is an empty string, string is returned unchanged.

type A string containing one of the following characters (the default is "R".):

A Removes all occurrences of removeChar.

B Removes both leading and trailing occurrences of removeChar.

L Removes all leading occurrences of removeChar.

M Replaces multiple consecutive occurrences with a single character. Does not remove single leading and trailing occurrences.

R Removes leading and trailing occurrences of removeChar and replaces multiple consecutive occurrences with a single character.

This behaviour can be changed with the TRIM.R2M compatibility option.

T Removes all trailing occurrences of removeChar.

Only the first character in type is significant; subsequent characters are ignored.

Note

If keyword case-insensitivity is selected, this parameter can be in upper or lower case. Otherwise, it must be upper case.

Note

If string comprises removeChar only, the TRIM function trims to a null string. For example:

X = "AAAA"
Y = TRIM(X, "A", "R")

Assigns ' ' to variable Y.

Shorthand Forms

The TRIMB and TRIMF functions are shorthand forms of the TRIM function:

Examples

NEW.STR = TRIM(OLD.STR, @AM, 'T')

Removes all trailing attribute marks from OLD.STR and assigns the new string to NEW.STR.

X = "@@@BB@@@CC@@@"
Y = TRIM(X, "@")
PRINT Y

Removes leading and trailing occurrences of "@" and replaces multiple consecutive occurrences with a single character; prints the string BB@CC.

STR1 = "1230010029911"
X = TRIM(STR1, "1", 'A')
PRINT X

Removes all occurrences of the number 1 and prints the string 230000299.