Re: Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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

Re: Converting characters to "ascii" value

2006-03-19 Thread Frank W. Zammetti
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

Re: Converting characters to "ascii" value

2006-03-19 Thread Leon Rosenberg
> 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

Re: Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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

Re: Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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

Re: Converting characters to "ascii" value

2006-03-19 Thread Nic Daniau
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

Re: Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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

Re: Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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 -

Re: Converting characters to "ascii" value

2006-03-19 Thread Frank W. Zammetti
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

Re: Converting characters to "ascii" value

2006-03-19 Thread Artur Rataj
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 --

Converting characters to "ascii" value

2006-03-19 Thread David Kerber
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