TRIM

TRIM


TRANSACTION START Index Level TRIMB
Syntax TRIM( string.expression, {trimchar {,type}} )
Category BASIC
Type Function
Description removes leading, trailing, and/or redundant characters from a string.

If only one parameter is specified, then "trim" removes all leading and trailing blanks from a string expression, and compresses multiple embedded blanks to one embedded blank.

If the "trimchar" character is specified (available on release 7.0 and higher), then that character substitutes for the space. If the "type" parameter is missing, then type R is assumed.

If the "type" parameter is specified (available on release 7.0 and higher), then the trim behavior can be controlled more specifically.  Available values are:

L  trim leading
T  trim trailing
B  trim leading and trailing
A  trim all
R  trim redundant
Options
See Also statements & functions string.expression functions
Example string = trim("   cat   dog   bird   ")

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

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

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

The following 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')

Would produce the following output:
-a-b-c
a--b--c--
--a--b--c
a--b--c
abc
-a-b-c-
Warnings
Compatibility D3 7.0 R83 R91
TRANSACTION START Index Level TRIMB