Routines (alphabetical) > Routines: I > IDL_VALIDNAME

# 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.

## Examples

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']

## 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, an empty 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:

- All non-alphanumeric characters (except “_”, “!” and “$”) are converted to underscores
- If the first character is a number or a “$”, then an underscore is prepended to the string
- If the first character is not a valid character (“_”, “!”, “A”…“Z”) then that character is converted to an underscore
- If the element of String is an empty string or a reserved word (such as “AND”) then an underscore is prepended to the string

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.

### 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 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.

## Version History

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

## See Also

CREATE_STRUCT