STRING function returns its arguments converted to string type. It is similar to the PRINT procedure, except that its output is placed in a string rather than being output to the terminal. The case in which a single expression of type byte is specified without the FORMAT keyword is special--see the discussion below for details.
Result = STRING(
, ..., Expression
The expressions to be converted to string type.
Set this keyword to specify that any special case processing should be ignored and that STRING should behave exactly as the PRINT procedure would.
Differences Between STRING and PRINT
The behavior of STRING differs from the behavior of the PRINT procedure in the following ways (unless the PRINT keyword is set):
When called with a single non-byte argument and no format specification, STRING returns a result that has the same dimensions as the original argument. For example, the statement:
gives the result:
<Expression> STRING = Array
HELP, STRING(INDGEN(5), /PRINT)
<Expression> STRING =' 0 1 2 3 4'
If called with a single argument of byte type and the FORMAT keyword is not used, STRING simply stores the unmodified values of each byte element in the result. This result is a string containing the byte values from the original argument. Thus, the result has one less dimension than the original argument. For example, a 2-dimensional byte array becomes a vector of strings, a byte vector becomes a scalar string. However, a byte scalar also becomes a string scalar. For example, the statement:
PRINT, STRING([72B, 101B, 108B, 108B, 111B])
produces the output:
because the argument to STRING, is a byte vector. Its first element is a 72B which is the ASCII code for "H", the second is 101B which is an ASCII "e", and so forth.
If both the FORMAT and PRINT keywords are not present and STRING is called with more than one argument, and the last argument is a scalar string starting with the characters "$(" or "(", this final argument is taken to be the format specification, just as if it had been specified via the FORMAT keyword. This feature is maintained for compatibility with version 1 of VMS IDL.
To convert the contents of variable A to string type and store the result in the variable B, enter:
B = STRING(A)