Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my task is when i enter the alphabet i should get the number
for e.g: I Entered "D" then It should show the "4" this is my task can any one help to me
Posted
Comments
Wombaticus 15-Apr-15 5:37am    
Try casting it to int, for starters...
Thanks7872 15-Apr-15 5:38am    
We don't do your homework. It's 'your' task, not ours.
Member 11416690 15-Apr-15 6:00am    
i tried i did't get.that's why i am asking
Abhinav S 15-Apr-15 5:49am    
What have you tried so far?

1 solution

Um...have you ever considered the complicated maths operation called "subtraction"?

Try:
C#
string inp = "ABCD";
foreach (char c in inp.ToUpper())
    {
    if (c >= 'A' && c <= 'Z')
        {
        Console.WriteLine("The \"number\" of '{0}' is {1}", c, c - 'A' + 1);
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900