The IDL_VALIDNAME function determines whether a string may be used as a valid IDL variable name or structure tag name. Optionally, the routine can convert non-valid characters into underscores, returning a valid name string.
Result = IDL_VALIDNAME(String [, /CONVERT_ALL] [, /CONVERT_SPACES])
Returns the input string or strings, optionally converting all spaces or non-alphanumeric characters to underscores. If an input string cannot be used as a valid variable or structure tag name, an empty string is returned.
A scalar string or string array or representing the IDL variable or structure tag names to be checked.
If this keyword is set, then each element of String is converted into a valid IDL variable name using the following rules:
Tip: The CONVERT_ALL keyword guarantees that a valid variable name is returned. It is useful in converting user-supplied strings into valid IDL variable names.
If this keyword is set, then all spaces within each element of String are converted to underscores. If an element of String contains any other non-alphanumeric characters, then an empty string is returned, indicating that the string cannot be used as a valid variable name.
Note: CONVERT_SPACES behaves the same as CREATE_STRUCT when checking structure tag names.
The following table provides IDL_VALIDNAME examples and their results.
Example |
Result |
IDL_VALIDNAME('abc') |
'abc' |
IDL_VALIDNAME(' a b c ') |
'' |
IDL_VALIDNAME(' a b c ', /CONVERT_SPACES) |
'_a_b_c_' |
IDL_VALIDNAME('$var') |
'' |
IDL_VALIDNAME('$var', /CONVERT_ALL) |
'_$VAR' |
IDL_VALIDNAME('and') |
'' |
IDL_VALIDNAME('and', /CONVERT_ALL) |
'_AND' |
IDL_VALIDNAME(['and', 'or'], /CONVERT_ALL) |
['_AND', '_OR'] |
6.0 |
Introduced |
6.4 |
Modified to accept string arrays as well as scalar strings |