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. ... |
Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.