fpoyavo
asked on
simple one
Hi Experts,
Is there ready class in C# so that I can get a number instead of letter.
Example: I pass "a" and get "1"
pass "b" and get "2"
pass "c" and get "3" ....etc
Thank you.
Is there ready class in C# so that I can get a number instead of letter.
Example: I pass "a" and get "1"
pass "b" and get "2"
pass "c" and get "3" ....etc
Thank you.
double d = char.GetNumericValue('1');
Cheers
Jatinder
Cheers
Jatinder
Hi,
You can use this method:
private int CharToInt(char ch)
{
return (int)ch - (int)'a' + 1;
}
Gena
You can use this method:
private int CharToInt(char ch)
{
return (int)ch - (int)'a' + 1;
}
Gena
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Class CharToNumber
{
public CharToNumber
{}
public static int getInt(char charValue)
{
switch (charValue)
{
case 'a':
return 1;
break;
case 'b':
return 2;
break;
......
default:
break;
}
}
you can call this without declaring an object
main()
{
int x = CharToNumber.getInt('a');
}
Hope, this helps you
Cheers
Vadivel Kumar