STRTRIM

The STRTRIM function returns a copy of String with leading and/or trailing blanks removed.

Calling Sequence

Result = STRTRIM( String, [Flag] )

Arguments

String

The string to have leading and/or trailing blanks removed. If this argument is not a string, it is converted using IDL's default formatting rules. If it is an array, the result is an array with the same structure where each element contains a trimmed copy of the corresponding element of String .

Flag

A value that controls the action of STRTRIM. If Flag is zero or not present, trailing blanks are removed. Leading blanks are removed if it is equal to 1. Both are removed if it is equal to 2.

Example

Converting variables to string type often results in undesirable leading blanks. For example, the following command converts the integer 56 to string type:

C = STRING(56)

Entering the command:

HELP, C

IDL prints:

C         STRING = '      56'

which shows that there are six leading spaces before the characters 5 and 6. To remove these leading blanks, enter the command:

C = STRTRIM(C, 1)

To confirm that the blanks were removed, enter:

HELP, C

IDL prints:

C         STRING = '56'

See Also

STR_SEP , STRMID , STRPOS , STRPUT