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

How to convert character to integer

1,721 views
Skip to first unread message

Mallikarjunarao Kosuri

unread,
May 20, 2012, 3:13:13 AM5/20/12
to
Hi,

I want convert a character into integer how we can did this in TCL?

Thanks
Malli

Andreas Leitgeb

unread,
May 20, 2012, 3:29:25 AM5/20/12
to
Mallikarjunarao Kosuri <mall...@gmail.com> wrote:
> I want convert a character into integer how we can did this in TCL?

set char "*";# its unicode-point is 42

# save integer in variable "num":
scan $char "%c" num
puts $num;# prints 42

# directly return the integer:
scan $char "%c";# returns 42

Mallikarjunarao Kosuri

unread,
May 21, 2012, 1:04:24 AM5/21/12
to
Thanks dude, I need Integer to char?

Mallikarjunarao Kosuri

unread,
May 21, 2012, 3:12:08 AM5/21/12
to
On Sunday, May 20, 2012 12:43:13 PM UTC+5:30, Mallikarjunarao Kosuri wrote:
Thanks i got it
% format %c [expr [scan c %c]+1]
d

Andreas Leitgeb

unread,
May 21, 2012, 5:17:57 AM5/21/12
to
Mallikarjunarao Kosuri <mall...@gmail.com> wrote:
> On Sunday, May 20, 2012 12:43:13 PM UTC+5:30, Mallikarjunarao Kosuri wrote:
>> I want convert a character into integer how we can did this in TCL?
> Thanks i got it
> % format %c [expr [scan c %c]+1]
> d

Better curly-brace the expression:
format %c [expr {[scan c %c]+1}]

It's generally a good rule of thumb to *always* brace the expression.
(The only exceptions are, where substituted values become part of
the expression, rather than just operands.)

In this case, adding the curlies will just give you improved
performance. In many other cases, using braced expressions will
avoid bugs, too.

0 new messages