A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Need help about incrementing a string

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    83

    Need help about incrementing a string

    I'm trying to make a dynamic table. First I thought about using Matrix class but then decided to use a1 a2 a3 and so on for the cell names.

    I want to increment the string.

    Code:
    var letter:String="a";
    letter++;
    This doesn't work. Can anyone help me?
    Last edited by onurcan1977; 10-27-2010 at 01:43 PM. Reason: added var line

  2. #2
    Member
    Join Date
    Nov 2007
    Posts
    83
    Ok, I found a solution, I'm using array.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Not that it matters since you found a way, but nothing about that made any sense.

    What would a Matrix have to do with a table? What does it mean to increment a String? And what was your solution with array to what actual problem?

    If by "increment a string" you mean "increment a character stored in a string to the character with the next higher charCode", you could do it like this:

    Code:
    var letter:String = "a";
    function getNextLetter(input:String):String{
      return String.fromCharCode(input.charCodeAt(0)+1));
    }
    
    letter = getNextLetter(letter);
    Note that Strings are immutable, so getNextLetter returns a NEW String with the desired value. Note also that if you pass it a String with more or less than 1 character, you get nonsense output, or an error.

  4. #4
    Member
    Join Date
    Nov 2007
    Posts
    83
    That was exactly what I was looking for. Thanks a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center