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

incr on characters in Tcl?

1 view
Skip to first unread message

Holger

unread,
May 30, 1999, 3:00:00 AM5/30/99
to
I have the need to increment characters, which is not accepted as
valid Tcl code. If the variable x contains the letter 'a', I would like
to increment it to 'b' and so on. In C this is no problem, in Pascal
there is the succ() function, but how can I do this in Tcl without
writing a C function, which would be too much of a hassle, because
I want to use my script under UniX and Windows, and I lack a
C compiler for Windows.

ThanX in advance

Holger

Hume Smith

unread,
May 30, 1999, 3:00:00 AM5/30/99
to
Holger <hol...@2die4.com> wrote:
>I have the need to increment characters, which is not accepted as
>valid Tcl code. If the variable x contains the letter 'a', I would like
>to increment it to 'b' and so on

off the top o me head - disgusting

proc cincr {var {val 1}} {
upvar 1 $var x
if {1==[scan $x %c y]} { set x [format %c [incr y $val]] }
}

you may be better keeping an integer, applying incr to that, and using format.

0 new messages