Previous IDL Reference Guide: Procedures and Functions Next

IDL_VALIDNAME

Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

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 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, a null string is returned.

Arguments

String

A scalar string or string array or representing the IDL variable or structure tag names to be checked.

Keywords

CONVERT_ALL

If this keyword is set, then each element of String is converted into a valid IDL variable name using the following rules:

CONVERT_SPACES

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 a null 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.

Examples

The following table provides IDL_VALIDNAME examples and their results.

Table 3-49: IDL_VALIDNAME Examples

Table 3-49: IDL_VALIDNAME Examples
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']  

Version History

6.0
Introduced
6.4
Modified to accept string arrays as well as scalar strings

See Also

CREATE_STRUCT

  IDL Online Help (March 06, 2007)