LPM: java ?

0x29A [B.Vandgrift] booberry at io.com
Mon May 1 09:36:28 CDT 2000


On Mon, 1 May 2000, Joe Hourcle wrote:

=>> I know this is perl, but since perl has a nice easy way to do this, Im
=>> hoping someone knows the java way to do this.
=>> 
=>> 1) convert a char into an int
=>> 2) convert a string into an int
=>

I didn't see a response to this in java, so here it goes:
---
//TO convert from String to int:
String someNumber="987";
int foo;

try {
    foo = (new Integer(someNumber)).intValue();
} catch (NumberFormatException nfe) {
    // ouch.  Not a properly formatted integer. 
} 

   
// foo now = 987;

// to convert from Character to int:
char c= '9';
foo = (new Character(c)).getNumericValue();

if (foo == -2) {
	// character has no non-negative int value
} else if (foo == -1) {
	// character has no int value
} else {
	// you're good to go, foo = 9, in this case.
}

--

Hope this helps.



-- 
Ben Vandgrift <booberry at io.com>              http://www.io.com/~booberry
________________________________________________________________________
"I do not feel obliged to believe that the same God who has endowed us
 with sense, reason, and intellect has inteded for us to forego their
 use."                                                       --Galileo

     "These lightweights just can't hold their evil." --Bun-Bun




More information about the Lexington-pm mailing list