I know Ascii value isn't quite the correct term, but it's the only one
I could come up with.
What Im trying to come up with is the simplest way of coming up with the
numeric value associated with a given character, and to go back the
other direction as well. In VB, these are the ASC() and
Thanks!
Artur Rataj wrote:
char is a numeric type. You might try this code as an example:
char c = 32;
c += '@';
if(c 31) System.out.println(c + = + (int)c);
The exception is it adds to strings as a character, thus the cast is needed.
Regards,
Artur
I've never used char types; I'm so used to using Strings I don't even
think of it. Thanks!
Frank W. Zammetti wrote:
The first 127 characters of Unicode are in fact ASCII (might be the
first 255, I'm not sure, but the first 127 for sure). In other words,
it you do:
int i = (int)'A';
Not a char, a String (or more specifically, a specific character
extracted from a String).
Nic Daniau wrote:
Hum... I am missing something or you just want to cast a char to a byte/int
in Java?
char x = 'B'; // or Bravo.charAt(0) if you start with a string
byte y = (byte) x;
Integer myInt = myString.asc( myString.substring( 1, 2 )) // would
return 66 if the asc() method existed
int b = (int)myString.charAt(1);
or, in 1.5
int b = (int)(myString.substring(1,2).charAt(0)));
?
in java you don't need asc, since each char can be assign to an
integer an vice versa