Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASCII - Code of a char

1 view
Skip to first unread message

Peter Soppe

unread,
Oct 6, 1998, 3:00:00 AM10/6/98
to
Hello,

Does anyone know, how to get the ASCII-Value of a Character,
e.g. Char "A" = 65

Peter

Pascal Bouvier

unread,
Oct 6, 1998, 3:00:00 AM10/6/98
to

% scan A %c var
1
% set var
65


Pascal

vi...@party.fe.msk.ru

unread,
Oct 6, 1998, 3:00:00 AM10/6/98
to
Peter Soppe (so...@uni-muenster.de) wrote:
: Hello,

: Does anyone know, how to get the ASCII-Value of a Character,
: e.g. Char "A" = 65

proc get_code {char} {
scan $char "%c" code
return $code
}

%get_code "A"
65

: Peter

--
--------------------------------------------------
Victor Wagner vi...@ice.ru
Programmer Office:7-(095)-333-2022
Institute for Commerce Home: 7-(095)-135-46-61
Engineering http://www.ice.ru/~vitus

Evan Rempel

unread,
Oct 6, 1998, 3:00:00 AM10/6/98
to
In article <6vdboe$dtp$4...@zware.space.ru>, vi...@party.fe.msk.ru says...

>
>Peter Soppe (so...@uni-muenster.de) wrote:
>: Hello,
>
>: Does anyone know, how to get the ASCII-Value of a Character,
>: e.g. Char "A" = 65
>proc get_code {char} {
> scan $char "%c" code
> return $code
>}
>
>%get_code "A"
>65

that works great until you want to get the code for the
null character (ASCII 0)
% proc get_code {char} {


scan $char "%c" code
return $code
}

% puts [get_code A]
65
% puts [get_code \x01]
1
% puts [get_code \x00]
can't read "code": no such variable
%

I would suggest that this is a bug, since the character really
is there.

% string length "\x00"
1

Evan Rempel


vi...@party.fe.msk.ru

unread,
Oct 7, 1998, 3:00:00 AM10/7/98
to
Evan Rempel (idontt...@uvic.ca) wrote:
: >proc get_code {char} {

: > scan $char "%c" code
: > return $code
: >}
: >
: >%get_code "A"
: >65

: that works great until you want to get the code for the
: null character (ASCII 0)

: I would suggest that this is a bug, since the character really
: is there.

Of course, this is a bug. But this version would work in Tcl 7.x
for anything but NULLs
for Tcl 8.0
use

proc get_code {char} {
binary scan $char c1 code
return $code
}

you can ever do

if {[info tclversion]>=8.0} {
proc get_code {char} {
binary scan $char c1 a
return $a
}
} else {
proc get_code {char} {
if {[scan $char "%c" a]==1} {
return $a
} else {
return 0
}
}
}

This works for NUL in Tcl 7.5 and Tcl 8.0

0 new messages