Indeed it is!
Frank W. Zammetti wrote:
String myString = "ABCDEFG";
int myInt = (int)myString.charAt(1);
Even simpler than VB :)
Frank
David Kerber wrote:
To be more specific than my last message, my ultimate goal is to be
able to do something like:
String myString = "ABCDEFG"
Integer
String myString = "ABCDEFG";
int myInt = (int)myString.charAt(1);
Even simpler than VB :)
Frank
David Kerber wrote:
To be more specific than my last message, my ultimate goal is to be able
to do something like:
String myString = "ABCDEFG"
Integer myInt = myString.whateverMethod( myString.su
> 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
L
To be more specific than my last message, my ultimate goal is to be able
to do something like:
String myString = "ABCDEFG"
Integer myInt = myString.whateverMethod( myString.substring( 1, 2 ))
// should return 66
I can do this by going through a byte[], but was looking for a more
straight f
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;
System.out.pr
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;
System.out.println("y=" + y); // should give you 66
and vice-versa:
char z = (char) y;
System.out.println("z=" + z); // should
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';
will
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
-
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';
will result in i=65, the ASCII value for A. char is a numeric type
remember, so you don't really have to cast to int, I just
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 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 c
11 matches
Mail list logo