IDL_VALIDNAME
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.
Syntax
Result = IDL_VALIDNAME(String [, /CONVERT_ALL] [, /CONVERT_SPACES])
Return Value
Returns the input string, optionally converting all spaces or non-alphanumeric characters to underscores. If the input string cannot be used as a valid variable or structure tag name, a null string is returned.
Arguments
String
A string representing the IDL variable or structure tag name to be checked.
Keywords
CONVERT_ALL
If this keyword is set, then String is converted into a valid IDL variable name using the following rules:
- All non-alphanumeric characters (except `_', `!' and `$') are converted to underscores
- If the first character of String is a number or a `$', then an underscore is prepended to the string
- If the first character of String is not a valid character (`_', `!', `A'...'Z') then that character is converted to an underscore
- If String is an empty string or a reserved word (such as "AND") then an underscore is prepended to the string
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.
CONVERT_SPACES
If this keyword is set, then all spaces within String are converted to underscores. If String contains any other non-alphanumeric characters, then a null string is returned, indicating that the string cannot be used as a valid variable name.
CONVERT_SPACES behaves the same as CREATE_STRUCT when checking structure tag names.
Examples
The following table provides IDL_VALIDNAME examples and their results.
|
Example
|
Result
|
result = IDL_VALIDNAME('abc')
|
'abc'
|
result = IDL_VALIDNAME(' a b c ')
|
''
|
result = IDL_VALIDNAME(' a b c ', /CONVERT_SPACES)
|
'_a_b_c_'
|
result = IDL_VALIDNAME('$var')
|
''
|
result = IDL_VALIDNAME('$var', /CONVERT_ALL)
|
'_$VAR'
|
result = IDL_VALIDNAME('and')
|
''
|
result = IDL_VALIDNAME('and', /CONVERT_ALL)
|
'_AND'
|
Version History
Introduced: 6.0
See Also
CREATE_STRUCT
Analysis Object Classes