• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

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.
0
fpoyavo
Asked:
fpoyavo
1 Solution
 
vadivhereCommented:
I dont think so, but this is very easy to make one.

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

         

0
 
jatinderalaghCommented:
double d = char.GetNumericValue('1');

Cheers
Jatinder
0
 
gena17Commented:
Hi,

You can use this method:

private int CharToInt(char ch)
{
      return (int)ch - (int)'a' + 1;
}

Gena
0
 
sun4sundayCommented:

This will return the number

private int CharToInt(char alphabet)
{
     int num = (int)  alphabet - 96 ;
     return num;
}

Hope this helps

sun4sunday


0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now