Velocity Reviews > Java > Convert numeric String into Integer (Java)

# Convert numeric String into Integer (Java)

Azmie
Guest
Posts: n/a

 12-28-2003
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.

Sudsy
Guest
Posts: n/a

 12-28-2003
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.

VisionSet
Guest
Posts: n/a

 12-28-2003

"Azmie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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

Thomas Schodt
Guest
Posts: n/a

 12-28-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Azmie) wrote in
news:(E-Mail Removed) m:

> 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

Dan Ackroyd
Guest
Posts: n/a

 12-28-2003

String szSomeString = "0000075";
int nSomeNumber;

nSomeNumber = Integer.getInteger( szSomeString ) ;

nSomeNumber now equals 75....

danack

"Azmie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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.

VisionSet
Guest
Posts: n/a

 12-28-2003

"Dan Ackroyd" <(E-Mail Removed)> wrote in message
news:bsn55m\$2ej\$(E-Mail Removed)...
>
> 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

Roedy Green
Guest
Posts: n/a

 12-28-2003
On 28 Dec 2003 08:43:22 -0800, (E-Mail Removed) (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.

Andrew Thompson
Guest
Posts: n/a

 12-29-2003
"VisionSet" <(E-Mail Removed)> wrote in message
news:C6EHb.12029\$(E-Mail Removed)...
> "Azmie" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
> > 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!

nos
Guest
Posts: n/a

 12-29-2003

"Roedy Green" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> On 28 Dec 2003 08:43:22 -0800, (E-Mail Removed) (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);

Andrew Thompson
Guest
Posts: n/a

 12-29-2003
"nos" <(E-Mail Removed)> wrote in message
newstLHb.64476\$VB2.125226@attbi_s51...
> > On 28 Dec 2003 08:43:22 -0800, (E-Mail Removed) (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);
......

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post news ASP General 2 05-26-2010 11:58 AM Randy Kramer Ruby 12 10-25-2007 09:56 PM yinglcs@gmail.com Python 2 01-22-2007 10:02 PM silverburgh.meryl@gmail.com C++ 8 02-01-2006 05:20 PM ief@specialfruit.be C++ 5 06-30-2005 01:08 PM

Advertisments