Hi, I am rather new to Tcl. I do have the Ousterhout book, but I
can't seem to find the the command that gives me the ASCII value of a
character. I want something like:
set asciiValue [ascii [string index myString 4]]
E-mail to me at tim...@metronet.com. Thanks.
-T
scan $char %c asciiValue
--
Jeffrey Hobbs Office: 541/346-3998
Univ of Oregon CIS GRF email: jho...@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~jhobbs/
This one is a bit tricky.
Here is one solution (no doubt there are better ones).
First, set up an array : char -> ascii (at the global level)
for {set i 1} {$i < 128} {incr i} {
set arr([format %c $i]) $i
}
and then define ascii :
proc ascii {c} {
uplevel #0 set arr($c)
}
[tested with tcl7.4]
You may also want to go beyond ASCII and cope also with
characters > 7 bits (we are billions out there whose
language need more than 7 bits values :-)
>E-mail to me at tim...@metronet.com. Thanks.
posted and emailed.
--
Marc Thirion -- Linux -- | 150 Bd Deodat de Severac
work: thi...@verilog.fr (preferred) | 31300 Toulouse, France
home: 10074...@compuserve.com | (33) 61 42 01 30
Try:
scan [string index myString 4] %c asciiValue
Although you might really want:
set myString testme
scan [string index $myString 4] %c asciiValue
**********************************************************************
* Gerald W. Lester | Voice: +1 (504)-889-2784 *
* Computerized Processes Unlimited, Inc. | FAX: +1 (504)-889-2799 *
* 4200 S. I-10 Service Rd., Suite 205 | E-Mail: g...@cpu.com *
* Metairie, LA 70001 | WWW: http://www.cpu.com *
* "Consulting System Integrators" *
**********************************************************************
Why not just do:
tcl>set myString "This is a test"
tcl>scan [string index myString 4] "%c" asciiValue
1
tcl>puts $asciiValue
114
Of course, you perhaps don't want the decimal value of the character -
you would have to convert that number then.
--
:s Larry W. Virden INET: lvi...@cas.org
:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.