You can do something similar based on ascii character values:
char[26] alphabet; for(int i = 0; i <26; i++) { alphabet[i] = (char)(i+65);
(see the table here .) You simply throw from the int value of the character into the character value - but this only works for ascii characters of different languages, etc.
EDIT: As suggested by Mehrdad in a comment on a similar solution, it is better to do this:
alphabet[i] = (char)(i+(int)('A'));
This causes the character A to assign an int value to it, and then increment it based on this, so it is not hard-coded.
xan Nov 24 '08 at 15:35 2008-11-24 15:35
source share