trim() function

The trim() function removes leading, trailing, and/or redundant characters from a string.


trim(str.exp, {trimchar{,type}})


str.exp String from which the specified characters are removed.
trimchar Specifies the specific leading, trailing, or redundant character to trim. If specified, then that character substitutes for the space.
type If specified, then the trim() behavior can be controlled more specifically. If not specified, then type R is assumed. Available values are:
A Trim all.
B Trim leading and trailing.
L Trim leading.
T Trim trailing.
R Trim redundant.


If only one parameter is specified, trim() removes all leading and trailing spaces from a string expression, and compresses multiple embedded spaces to one embedded space.


After trimming, string contains: "cat dog bird".

string = trim(" cat dog bird ")

In this case, the trim() function is used to convert fixed length fields to variable length fields by removing trailing and leading spaces.

readt record else stop
name = trim(record[1,25])
address = trim(record[26,40])

The program:

line = ’--a--b--c--’
print trim(line,’-’)
print trim(line,’-’,’L’)
print trim(line,’-’,’T’)
print trim(line,’-’,’B’)
print trim(line,’-’,’A’)
print trim(line,’-’,’R’)

produces the output: