?
Solved

simple one

Posted on 2005-03-09
4
Medium Priority
?
189 Views
Last Modified: 2010-04-16
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
Comment
Question by:fpoyavo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:vadivhere
ID: 13502787
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
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13502969
double d = char.GetNumericValue('1');

Cheers
Jatinder
0
 
LVL 8

Expert Comment

by:gena17
ID: 13503688
Hi,

You can use this method:

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

Gena
0
 
LVL 9

Accepted Solution

by:
sun4sunday earned 1000 total points
ID: 13504156

This will return the number

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

Hope this helps

sun4sunday


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question