Í know this should be easy but sometimes you just cant see the light.
I have string that I need to move to integer variable if it is integer?
Any idea
Icesoft
Printable View
Í know this should be easy but sometimes you just cant see the light.
I have string that I need to move to integer variable if it is integer?
Any idea
Icesoft
String s = "1234";
int mynumber;
try
{
mynumber = Integer.parseInt(s);
}
catch (NumberFormatException e)
{
System.out.println("That was not a number");
}
i would use a function:
...that should work just fine.Code:public int castToInt( String str )
{
return( new Integer( str ).intValue() );
}