Article View: aus.computers.java
Article #315Re: Help! String as Integer
From: Chris Smith
Date: Thu, 31 May 2001 22:55
Date: Thu, 31 May 2001 22:55
21 lines
1672 bytes
1672 bytes
> Luke Vanderfluit <luke@chipcity.com.au> wrote ...
> > I need to interpret a line of text as an integer.
> >
Using what conversion?
> > String a = "yes";
> > String b = "ls";
> > int aa = Integer.valueOf("foo").intValue();
> > int bb = Integer.valueOf("bar").intValue();
> > System.out.println(aa);
> > System.out.println(bb);
> >
> > This throws a NumberFormatException
As well it should, since neither "foo" nor "bar" are valid integer values.
What integer value do you want to get back? For one possible integer value,
you could use "foo".hashCode(), but that may not be what you want. What
*do* you want?
Chris Smith
Technical Details
Message-ID:
<9f6i6i$h5d$0@dosa.alt.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.alt.net!usenetReferences:
<3A63FC90.3C832EFA@chipcity.com.au> <3b16b1bd_3@news.bizonline.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,5f124143cc4771e2 X-Google-Attributes: gid10a146,public X-Google-Thread: 10d6db,7de64e08ee658586 X-Google-Attributes: gid10d6db,public X-Google-Thread: 113ae9,7de64e08ee658586 X-Google-Attributes: gid113ae9,public X-Google-ArrivalTime: 2001-05-31 15:56:19 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.alt.net!usenet From: "Chris Smith" <cdsmith@twu.net> Newsgroups: aus.computers.java,comp.lang.java.programmer,comp.lang.java.help Subject: Re: Help! String as Integer Date: Thu, 31 May 2001 17:55:53 -0500 Organization: Altopia Corp. - Usenet Access - http://www.altopia.com Lines: 23 Message-ID: <9f6i6i$h5d$0@dosa.alt.net> References: <3A63FC90.3C832EFA@chipcity.com.au> <3b16b1bd_3@news.bizonline.net> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200