PreviousNext

Parsing Strings

The DCE control program includes a scan command that parses strings and then converts, and stores relevant parts of strings in variables. This capability is useful, for instance, when converting information returned by a previous command into data that can be input to another command. The syntax for the scan command is:

scan "string" "format" [varname [varname]...]

You can specify the string literally or by using a variable. The format section controls parsing, ignoring blanks and tab characters you might have included in the format section for readability. This section consists of one or more conversion specifiers delimited by percent signs (%). Conversion specifiers define which parts of string get converted and stored, as well as the type of conversion.

The following example parses the string contained in the variable _dcp_temp for a valid floating point number and stores it in the variable _dcp_temp2.

if { [scan $_dcp_temp "%f" _dcp_temp2] != 1 } {
error "Variable \"$_dcp_temp\" is not a valid floating
point number"
}