-
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
-
Ok, I found a solution, I'm using array.
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|