Okay - I want to convert a LETTER (char) into an NUMBER (int) given a set scheme...
Specifically - when string sInput = "0", "1", "2", "3", "4", "5", "6", "7", "8", and "9" I want to leave it as-is. However if sInput is a letter from "a" to "z" I want to convert it to a NUMBER using the simplest scheme that assign "a"=10, "b"=11, "c"=12, etc... all the way to "z"=35.
I have a working model (as shown in the code below) but I need to cover from 'a' to 'z' and covering all 25 cases as shown below would be ... ugly to say the least...
So I am looking for better ways to accomplish this task, maybe a way to create a for loop (25 times) and somehow increment the character value ???
Generally the idea is I have a textbox that allows for 3 characters, I want to add them together to get a total sum but I can't really do 1+a+z so I want to convert a=10 and z=35 so the math becomes 1+10+35=46
Any help would be greatly appreciated, thanks
Specifically - when string sInput = "0", "1", "2", "3", "4", "5", "6", "7", "8", and "9" I want to leave it as-is. However if sInput is a letter from "a" to "z" I want to convert it to a NUMBER using the simplest scheme that assign "a"=10, "b"=11, "c"=12, etc... all the way to "z"=35.
I have a working model (as shown in the code below) but I need to cover from 'a' to 'z' and covering all 25 cases as shown below would be ... ugly to say the least...
Code:
private string ConvertToNumber(string sInput)
{
char[] sOutput = sInput.ToUpper().ToCharArray();
// DO THE CONVERSION SCHEME //
if (sOutput == 'A')
return "10";
else if (soutput == 'B')
return "11";
...
...
else
{
sOutput = sInput;
}
// END OF THE CONVERSION SCHEME //
return sOutput[0].ToString();
}
Generally the idea is I have a textbox that allows for 3 characters, I want to add them together to get a total sum but I can't really do 1+a+z so I want to convert a=10 and z=35 so the math becomes 1+10+35=46
Any help would be greatly appreciated, thanks