TRIM function

Syntax

TRIM (expression [ ,character [ ,option] ] )

Description

Use the TRIM function to remove unwanted characters in expression. If only expression is specified, multiple occurrences of spaces and tabs are reduced to a single tab or space, and all leading and trailing spaces and tabs are removed. If expression evaluates to one or more space characters, TRIM returns an empty string.

character specifies a character other than a space or a tab. If only expression and character are specified, multiple occurrences of character are replaced with a single occurrence, and leading and trailing occurrences of character are removed.

option specifies the type of trim operation to be performed:

A
Remove all occurrences of character
B
Remove both leading and trailing occurrences of character
D
Remove leading, trailing, and redundant white space characters
E
Remove trailing white space characters
F
Remove leading white space characters
L
Remove all leading occurrences of character
R
Remove leading, trailing, and redundant occurrences of character
T
Remove all trailing occurrences of character

If expression evaluates to the null value, null is returned. If option evaluates to the null value, null is ignored and option R is assumed. If character evaluates to the null value, the TRIM function fails and the program terminates with a run-time error message.

If NLS is enabled, you can use TRIM to remove other white space characters such as Unicode values 0x2000 through 0x200B, 0x00A0, and 0x3000, marked as TRIMMABLE in the NLS.LC.CTYPE file entry for the specified locale.

Example

A="  Now is the time  for  all good men to"
PRINT A
PRINT TRIM(A)

This is the program output:

  Now is the time  for  all good men to
Now is the time for all good men to