Options

Increment character

LefteyedLefteyed Member Posts: 43
Hey Guys

How do you get the next character?

say that I have a, then I want b as the next.

I can convert a to integer:
a := 'a'; // number = 65
i := a[1] + 1; // number = 66

but how do I then convert i so that it becomes 'b'

Thanks

Best Answers

  • Options
    frischfrisch Member Posts: 20
    Answer ✓
    Exactly. Actually you can simplify your code, because you can assign different types to a Char variable.
    If you define MyVar as Char, you can do this:
    MyVar := 'a'; // number = 65
    MyVar += 1;
    

    After this, MyVar wil be b.

Answers

  • Options
    frischfrisch Member Posts: 20
    Answer ✓
    Exactly. Actually you can simplify your code, because you can assign different types to a Char variable.
    If you define MyVar as Char, you can do this:
    MyVar := 'a'; // number = 65
    MyVar += 1;
    

    After this, MyVar wil be b.
  • Options
    LefteyedLefteyed Member Posts: 43
    I was to focused on doing it in code, didn't think of checking the variable types.. Oh my :)

    Thanks guys.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    If you have a string (text or code) (no need for char-variable):


    TheString := 'AAA';
    TheString[1] := TheString[1] + 1; //[1] is the first char in the string

    MESSAGE('%1',TheString); // => BAA
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    frischfrisch Member Posts: 20
    kriki wrote: »
    If you have a string (text or code) (no need for char-variable):


    TheString := 'AAA';
    TheString[1] := TheString[1] + 1; //[1] is the first char in the string

    MESSAGE('%1',TheString); // => BAA
    Thanks kriki, didn't know this! :)
Sign In or Register to comment.