Version 9 of scan

Updated 2004-09-02 14:33:36 by lwv

See http://www.purl.org/tcl/home/man/tcl8.4/TclCmd/scan.htm for the formal man page for the Tcl command scan.

 scan $possiblyZeroedDecimal %d cleanInteger
 set cleanInteger [scan $possiblyZeroedDecimal %d]

The fact that leading zeroes induce octal parsing is an often-reported problem.


display and numeric format for ASCII characters. display and numeric format for ASCII characters. Scan provides the usual answer:

    foreach character {a A b B c} {
        scan $character %c numeric
        puts "ASCII character '$numeric' displays as '$character'."
    }

    ASCII character '97' displays as 'a'.
    ASCII character '65' displays as 'A'.
    ASCII character '98' displays as 'b'.
    ASCII character '66' displays as 'B'.
    ASCII character '99' displays as 'c'.        

In more recent Tcl's (8.3 or so up) you also can call scan inline:

 set numeric [scan $character %c]

And the %c format is not limited to ASCII, but can handle any Unicode. (RS)

LV Can someone explain what this means - calling scan inline? Where is scan getting its input in this case? From stdin?

Unmatched Conversion Specifiers


Also see "Dump a file in hex and ASCII", as well as "u2x" in the "Bag of algorithms".

Binary has a scan which complements use of this scan.

Effect on the Internal Representation of a Value


Tcl syntax help - Arts and crafts of Tcl-Tk programming - Category Command