Tip: See also the IDL_String::Trim method, which provides similar functionality but with an object-oriented interface.

The STRTRIM function removes leading and/or trailing blank from the input String.

Examples


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'

Syntax


Result = STRTRIM( String [, Flag] )

Return Value


Returns a copy of string with the specified blank spaces removed.

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.

Version History


Original

Introduced

See Also


String Operations, String Processing, STRCOMPRESS, STRMID, STRPOS, STRPUT, STRSPLIT, IDL_String