Reputation: 590
I have a char array, chars[]
with values {'#', '$', '1'}
contained within it. I want to remove the 1
and place it into another variable, val
, but when I do it gives me a 49 (idk why). I tried debugging it and the info shows that the elements of chars
are as follows:
char[0] = 35 '#'
char[1] = 36 '$'
char[2] = 49 '1'
Which in turn makes
int val = char[2];
become
val = 49
I'm not sure why this is, but it's throwing my plans off. Does anyone know what the problem is and what I can do to fix it?
Upvotes: 1
Views: 1983
Reputation: 76
Just go for: charArray[x].ToString();
This will convert the ASCII representation to an actual Character.
Upvotes: 0
Reputation: 2831
You should use
char val = char[2];
With int, you are getting the ASCII representation of the char as an integer. see also http://hu.wikipedia.org/wiki/ASCII
Upvotes: 2
Reputation: 26048
49 is the ASCII representation for the char '1'
link to ASCII table
Upvotes: 1