c# - Convert a Letter to its alphabet numerical Rank -
c# - Convert a Letter to its alphabet numerical Rank -
i trying convert letter alphabet numerical order illustration if have 'a' give me 00 or 'c' 02
how can code in c# ?
edit : tried
i created class :
public class alphabetletter { public char letter {get; set;} public int rank {get; set;} }
those 2 lists :
public list<char> letters = new list<char> { 'a' ,'b' ,'c' ,'d' ,'e', 'f' ,'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm', 'n' ,'o' ,'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' }; public list<int> ranks = new list<int> { 00,01,02,04,05,06,07,08,09,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25 }; public list<alphabetletter> alphabet = new list<alphabetletter>( );
i created alphabet in constructor :
for (int = 0; < 25; i++) { alphabet.add(new alphabetletter { rank = ranks[i], letter = letters[i] });
and tried match char function :
public int numberize(char letter) { if (letter != null) { foreach (alphabetletter _letter in alphabet) { if (letter == _letter.letter) { homecoming _letter.rank; } else { homecoming 896; } } } else { homecoming 999; } } }
but method not working , tedious.
any suggestions?
you start getting unicode value:
int charvalue = convert.toint32('a');
then business relationship 'a' on unicode table (65)
int rank = charvalue - 65;
note won't work lower case letters, in different position. utilize tolower
or toupper
on string version of character nullify (as in other answer).
c#
Comments
Post a Comment