Convert numeric String into Integer (Java)

Discussion in 'Java' started by Azmie, Dec 28, 2003.

  1. Azmie

    Azmie Guest

    Anyone can help me to solve this problem.
    I want to convert numeric string = "000000075" into Integer value = 75

    What is the best approach?

    Thanks in advance.
     
    Azmie, Dec 28, 2003
    #1
    1. Advertising

  2. Azmie

    Sudsy Guest

    Azmie wrote:
    > Anyone can help me to solve this problem.
    > I want to convert numeric string = "000000075" into Integer value = 75
    >
    > What is the best approach?
    >
    > Thanks in advance.


    Integer.parseInt( string );

    Suggestion: read the javadocs.
     
    Sudsy, Dec 28, 2003
    #2
    1. Advertising

  3. Azmie

    VisionSet Guest

    "Azmie" <> wrote in message
    news:...
    > Anyone can help me to solve this problem.
    > I want to convert numeric string = "000000075" into Integer value = 75
    >
    > What is the best approach?


    All you need to do is browse java.lang.Integer in the API docs for about 30
    seconds to arrive at the answer...

    int i = Integer.parseInt("00000075");

    or if you'd like that wrapped

    Integer i = Integer.valueOf("00000075");


    --
    Mike W
     
    VisionSet, Dec 28, 2003
    #3
  4. (Azmie) wrote in
    news::

    > I want to convert numeric string = "000000075" into Integer value = 75


    I assume you mean int, rather than Integer

    String s = "000000075";
    int n = Integer.parseInt(s);

    PS.
    Basic questions like this really belong in c.l.j.help
     
    Thomas Schodt, Dec 28, 2003
    #4
  5. Azmie

    Dan Ackroyd Guest

    String szSomeString = "0000075";
    int nSomeNumber;

    nSomeNumber = Integer.getInteger( szSomeString ) ;

    nSomeNumber now equals 75....

    danack

    "Azmie" <> wrote in message
    news:...
    > Anyone can help me to solve this problem.
    > I want to convert numeric string = "000000075" into Integer value = 75
    >
    > What is the best approach?
    >
    > Thanks in advance.
     
    Dan Ackroyd, Dec 28, 2003
    #5
  6. Azmie

    VisionSet Guest

    "Dan Ackroyd" <> wrote in message
    news:bsn55m$2ej$...
    >
    > String szSomeString = "0000075";
    > int nSomeNumber;
    >
    > nSomeNumber = Integer.getInteger( szSomeString ) ;
    >
    > nSomeNumber now equals 75....
    >
    > danack


    No, getInteger(String s) returns an Integer object,
    or throws an exception if s is not parsable

    --
    Mike W
     
    VisionSet, Dec 28, 2003
    #6
  7. Azmie

    Roedy Green Guest

    Roedy Green, Dec 28, 2003
    #7
  8. "VisionSet" <> wrote in message
    news:C6EHb.12029$...
    > "Azmie" <> wrote in message
    > news:...
    > > Anyone can help me to solve this problem.
    > > I want to convert numeric string = "000000075" into Integer value = 75

    ....
    > or if you'd like that wrapped


    Yes please, pretty paper, with a bow! ;-)
     
    Andrew Thompson, Dec 29, 2003
    #8
  9. Azmie

    nos Guest

    "Roedy Green" <> wrote in
    message news:...
    > On 28 Dec 2003 08:43:22 -0800, (Azmie) wrote or quoted
    > :
    >
    > >I want to convert numeric string = "000000075" into Integer value = 75
    > >

    >
    > see http://mindprod.com/converter.html
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


    if(s.equals("000000075")) i=new Integer(75);
     
    nos, Dec 29, 2003
    #9
  10. "nos" <> wrote in message
    news:ptLHb.64476$VB2.125226@attbi_s51...
    > > On 28 Dec 2003 08:43:22 -0800, (Azmie) wrote or quoted

    ....
    > > >I want to convert numeric string = "000000075" into Integer value = 75

    ...
    > if(s.equals("000000075")) i=new Integer(75);

    .....
    else if (s.equals("00000075")) i=new Integer(75);
    else if (s.equals("000075")) i=new Integer(75);
    else if (s.equals("00075")) i=new Integer(75);
    else if (s.equals("0075")) i=new Integer(75);
    else if (s.equals("075")) i=new Integer(75);
    else if (s.equals("75")) i=new Integer(75);
    else if (s.equals("00000076")) i=new Integer(76);
    ......
     
    Andrew Thompson, Dec 29, 2003
    #10
  11. Azmie

    ak Guest

    > ...
    > > > >I want to convert numeric string = "000000075" into Integer value =

    75
    > ..
    > > if(s.equals("000000075")) i=new Integer(75);

    > ....
    > else if (s.equals("00000075")) i=new Integer(75);
    > else if (s.equals("000075")) i=new Integer(75);
    > else if (s.equals("00075")) i=new Integer(75);
    > else if (s.equals("0075")) i=new Integer(75);
    > else if (s.equals("075")) i=new Integer(75);
    > else if (s.equals("75")) i=new Integer(75);
    > else if (s.equals("00000076")) i=new Integer(76);


    lol, the biggest if else construct!!!

    ____________

    http://reader.imagero.com the best java image reader.
     
    ak, Dec 29, 2003
    #11
  12. >> String szSomeString = "0000075";
    >> int nSomeNumber;
    >>
    >> nSomeNumber = Integer.getInteger( szSomeString ) ;
    >>
    >> nSomeNumber now equals 75....
    >>
    >> danack

    >
    > No, getInteger(String s) returns an Integer object,
    > or throws an exception if s is not parsable
    >


    Nope, getInteger(String s) uses s as the name of a system property and
    creates an Integer (or null) from its value. Does anyone actually use these
    methods, like Integer.getInteger() and Boolean.getBoolean()?
    Michiel
     
    Michiel Konstapel, Dec 29, 2003
    #12
  13. Azmie

    Azmie Guest

    Thanks to everyone. the simple way i do this is using parseint function.
    Happy new year...
     
    Azmie, Dec 30, 2003
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,334
    Ravi Teja
    Jan 22, 2007
  2. Replies:
    5
    Views:
    952
    X-Centric
    Jun 30, 2005
  3. Replies:
    8
    Views:
    675
    Marcelo Pinto
    Feb 1, 2006
  4. news
    Replies:
    2
    Views:
    1,116
  5. Randy Kramer
    Replies:
    12
    Views:
    383
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page