> 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
Leon

On 3/19/06, David Kerber <[EMAIL PROTECTED]> 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.substring( 1, 2 ))
> // should return 66
>
> I can do this by going through a byte[], but was looking for a more
> straight forward method, something like VB's asc() function:
>
> In VB:
> myInt = asc( mid$( myString, 2,1))   // returns 66
>
> Integer myInt = myString.asc( myString.substring( 1, 2 ))  // would
> return 66 if  the asc() method existed
>
>
>
> 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.println("y=" + y); // should give you 66
> >
> >and vice-versa:
> >char z = (char) y;
> >System.out.println("z=" + z); // should give you B
> >
> >The only thing you need to watch is the byte number, I think you get a
> >number between -128 and +127, so you may need to adjuct depending on your
> >needs.
> >
> >BTW I've not tested the code above, I'm just typing it as I speak.
> >
> >HTH
> >Nic
> >
> >On 19/03/06, David Kerber <[EMAIL PROTECTED]> wrote:
> >
> >
> >>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 chr()
> >>functions.  I know how to get these values by going through a Byte type,
> >>but is there a quicker way to get (for example):
> >>
> >>Starting with "B", return 66, or starting with " " (one space), return 32?
> >>Going the other way, 66 should return "B", and 32 should return " ".
> >>
> >>Thanks for any suggestions!
> >>DAve
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >>
> >>
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to