TRIM()

TRIM()

Top  Previous  Next

 

The TRIM() function removes excess characters from a string.

 

 

Format

 

TRIM(string)

TRIM(string, character{, mode})

 

where

 

stringevaluates to the string to be trimmed.

 

characteris the character to be removed

 

modeevaluates to a single character which determines the mode of trimming:
ARemove all occurrences of character.
BRemove all leading and trailing occurrences of character.
CReplace multiple instances of character with a single character.
DRemove all leading and trailing spaces, replacing multiple embedded spaces with a single space.  The value of character is ignored.
ERemove all trailing spaces.  The value of character is ignored.
FRemove all leading spaces.  The value of character is ignored.
LRemove all leading occurrences of character.
RRemove all leading and trailing occurrences of character, replacing multiple embedded instances of character with a single character.
TRemove all trailing occurrences of character.

 

 

The first format of the TRIM() function removes all leading and trailing spaces from string and replaces multiple embedded spaces by a single space.

 

The second form is more generalised and allows other characters to be removed.

 

 

Examples

 

X = "  1  2  3  "

Y = TRIM(X)

 

This program fragment removes excess spaces from string X setting Y to "1 2 3"

 

 

X = "ABRACADABRA"

Y = TRIM(X, 'A', 'A')

 

This program fragment removes all occurrence of the letter A from string X setting Y to "BRCDBR"

 

 

X = "ABRACADABRA"

Y = TRIM(X, 'A', 'B')

 

This program fragment removes leading and trailing occurrences of the letter A from string X setting Y to "BARCADABR"

 

 

See also:

TRIMB(), TRIMF(), TRIMS(), TRIMW()