The trim() function removes leading, trailing, and/or redundant characters from a string.
Syntax
trim(str.exp, {trimchar {,type}}) trim(str.exp, "process.code") |
Parameter(s)
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. |
|
process.code |
The process code is a masking conversion used for both numeric and text string formatting. |
|
l |
Left justification is used primarily for text strings |
|
r |
Right justification is typically used to process decimal numbers. |
|
format.mask |
Special fill operators listed below. Maximum 32,767. |
|
#n |
Justify data in a field of n spaces. |
|
*n |
Justify data in a field of n asterisks (*). |
|
%n |
Justify data in a field of n zeroes (0). |
Description
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.
Example(s)
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:
-a-b-c a--b--c-- --a--b--c a--b--c abc -a-b-c- |
See Also