Archive: Increment letter?


Increment letter?
Sounds silly but I haven't been able to find anywhere how to do this in NSIS:


StrCpy $R2 "A"
IntOp $R2 $R2 + 1
MessageBox MB_OK "R2 == $R2"


Message box displays "R2 == 1" instead of what I want: "R2 == B"

Is there a way to accomplish what I want in NSIS? Convert an ASCII 'A' to an int and vice versa?

Thanks!

(in C/C++ it's so easy but for the life of me I encountered a mental block trying to do this in NSIS)

You can use the Math Plugin for this (included with NSIS).
From the Math plugin readme:

c(source): if source is string, returns int value of first char, if source is int, returns string which consists of a single char (source) (+0 terminator).
To do what you want:
StrCpy $0 "A"
Math::Script "r1 = c(r0)" ; Convert first char &0 (r0) to integer into $1 (r1)
IntOp $1 $1 + 1
Math::Script "r0 = c(r1)" ; Convert integer $1 (r1) to char into $0 (r0)
MessageBox MB_OK $0

  StrCpy $R2 "A"
IntOp $R2 $R2 + 1
MessageBox MB_OK "R2 == $R2"
Message box displays "R2 == 1" instead of what I want: "R2 == B"
The wiki has a function that will help you do what you want: http://nsis.sourceforge.net/CharToASCII
  StrCpy $R2 "A"
${CharToASCII} $R2 $R2
IntOp $R2 $R2 + 1
IntFmt $R2 "%c" $R2
MessageBox MB_OK "$$R2 => $R2"

Thank you both, jpderuiter and pengyou. I eventually decided to go with pengyou's solution. It works very well.