-
Convert a string to an integer
Is there an aesy way to convert a string into an integer.
ie.
text "32" into the value 32
-
Re: Convert a string to an integer
"Snip Dadio" <j.murray@automotive-solutions.com> wrote:
>
>Is there an aesy way to convert a string into an integer.
>ie.
>text "32" into the value 32
One of a million ways...
String aString = new String("32");
Integer anInt = new Integer(0);
anInt = anInt.valueOf(aString);
anInt;
-
Re: Convert a string to an integer
"Snip Dadio" <j.murray@automotive-solutions.com> wrote:
>
>Is there an aesy way to convert a string into an integer.
>ie.
>text "32" into the value 32
Here's another of those million:
String s = "32";
int i = new Integer(s).intValue();
-
Re: Convert a string to an integer
>One of a million ways...
>
>
>String aString = new String("32");
>Integer anInt = new Integer(0);
>anInt = anInt.valueOf(aString);
>anInt;
Because 'valueOf' is static, you can use:
Integer anInt = Integer.valueOf(aString);
If you need an int rather than an Integer:
int anInt = Integer.valueOf(aString).intValue();
In Java 2, you can shorten it by:
int anInt = Integer.parseInt(aString);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|