Parsing a string using conversion specifiers
To parse a string in Tcl using conversion specifiers we will be using the scan
command. The scan
command parses the string in a similar manner as in the ANSI C sscanf
procedure. As the scan
command does not accept switches such as the regexp
and regsub
commands, we will proceed directly to the command. The syntax of the command is as follows:
scan string format variable variable variable…
The scan
command accepts a string to parse and based on the format provided, it will convert the string. If variables are provided, they will be updated to the output of the conversions.
The scan
command supports the following conversion characters:
Character |
Description |
---|---|
|
The input string must be a decimal integer. |
|
The input string must be an octal integer. |
|
The input string must be a decimal integer (as in the case of The output is assigned to the variable as an unsigned decimal string. |
|
The input substring consists of all the characters... |