Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello Everyone,
Is there a method of converting character to number
for example a = 1; b = 2; and so on,
 
Thanks in advance,
z3ngew
Posted 23-Jan-13 6:24am
z3ngew812
Edited 23-Jan-13 6:33am
v2
Comments
Sergey Alexandrovich Kryukov at 23-Jan-13 12:35pm
   
They are already numbers, a and b. :-)
—SA
z3ngew at 23-Jan-13 12:40pm
   
Perhaps i can use that , if the relation between the character values and their numerical values is linear
Sergey Alexandrovich Kryukov at 23-Jan-13 12:45pm
   
Linear, linear. You just don't explain it.
—SA
z3ngew at 23-Jan-13 12:48pm
   
I think your idea is very helpful, the values of the letters in ascii code are sequential, many thanks my freind
Andreas Gieriet at 23-Jan-13 13:49pm
   
Your questions are very difficult to decrypt. Looking at your other questions show a similar image.
It would help to get more useful answers if you try to pose the questions more precisely.
E.g. as Sergey already mentioned, a = 1 and b = 2 are not "characters". An you also do not answer to counter questions. Why? This is quite annoying.
Andi
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

char c = 'a' ;
int i = c - '`' ;
  Permalink  
Comments
z3ngew at 23-Jan-13 13:01pm
   
Works Great thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Use int.Parse or int.TryParse, but instead of int use any numeric type you like and then see the description of these two methods in MSDN help. Depending on content of the character data, it succeeds or not. As simple as that.
 
—SA
  Permalink  
Comments
z3ngew at 23-Jan-13 13:20pm
   
I'm sorry bu this method only convert strings that represent numbers like "1" or "2" etc. Thanks for you support
Sergey Alexandrovich Kryukov at 23-Jan-13 13:54pm
   
You are welcome. I even think that you can accept if formally (green button).
Please understand that this is a way to go, because this method is universal, agnostic to implementation detail...
—SA
Sergey Alexandrovich Kryukov at 23-Jan-13 13:56pm
   
Wait a second. Who told you it "only converts..."?! Read again...
—SA
Espen Harlinn at 23-Jan-13 19:42pm
   
5'ed!
Sergey Alexandrovich Kryukov at 23-Jan-13 19:45pm
   
Thank you, Espen.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Create an enumeration for your values then look at this article, Tips about .NET Enums[^], to see how to convert from the string representation (your char) to the corresponding value (integer) and back again.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100