conversion string[n] to int ?

  • Thread starter Thread starter user
  • Start date Start date
U

user

Hello
i have:
Sting s;
and it's first element is ASCII character which in ASCII code is equal
1. How can i convert it to byte ?
When i tried:
Convert.ToByte(s.substring(0,1),10);
it throught exception because first character in that string is not any
of characters '0'-'9'.

Thanx
 
i have:
Sting s;
and it's first element is ASCII character which in ASCII code is equal
1. How can i convert it to byte ?
When i tried:
Convert.ToByte(s.substring(0,1),10);
it throught exception because first character in that string is not any
of characters '0'-'9'.

If you're asking how to get the value of a character as a byte, you
just cast to byte - but be aware that the top 8 bits will be discarded:

byte x = (byte)(s[0]);
 
Back
Top