Jezyk Danzowki Jezyk Danzowki - 4 months ago 33
TypeScript Question

Angular2 Typescript how to increment alphabet index

I know how to do this in Php, as it is a simple, but i am struggling to get a version working.

for ($i = 'A'; $i < 'Z'; $i++) {
$k = $i;
$k++;
echo "$i->$k, ";
}


Basically i want to pass a letter into a function and get the next letter in the alphabet. Is there any easy ways or directions that i could be pointed in.

Answer

This should do what you want:

getNextLetter(char: String): String {
    code: Number = char.charCodeAt(0);
    code++;
    return String.fromCharCode(code);
}
Comments