Convert a string to an integer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Convert a string to an integer

  1. #1
    Snip Dadio Guest

    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

  2. #2
    mike Guest

    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;


  3. #3
    Tom Duffy Guest

    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();


  4. #4
    Ilja Preuß Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center