Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31464
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!feeder1.xsusenet.com!feeder2.news.elisa.fi!feeder1.news.elisa.fi!uutiset.elisa.fi!7564ea0f!not-for-mail |
|---|---|
| From | Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Integer.parseInt() and whitespace? |
| Organization | N/A |
| References | <3f229a4e-af34-424f-b256-2e806e71015a@googlegroups.com> <whitespace-20150405052154@ram.dialup.fu-berlin.de> |
| X-no-archive | yes |
| Content-Transfer-Encoding | 8bit |
| Message-ID | <lvpp7iyfsq.fsf@saunalahti.fi> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| Cancel-Lock | sha1:EnHQhduwqxWYPM7H/PfDz+C9IZc= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 21 |
| Date | Sun, 05 Apr 2015 14:29:09 +0300 |
| NNTP-Posting-Host | 91.155.88.191 |
| X-Complaints-To | newsmaster@saunalahti.com |
| X-Trace | uutiset.elisa.fi 1428233349 91.155.88.191 (Sun, 05 Apr 2015 14:29:09 EEST) |
| NNTP-Posting-Date | Sun, 05 Apr 2015 14:29:09 EEST |
| Xref | csiph.com comp.lang.java.programmer:31464 |
Show key headers only | View raw
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> galt_57@hotmail.com writes:
>>So Integer.parseInt(str) fails if the string contains whitespace?
> In that case java.lang.Integer.parseInt(java.lang.String)
> behaves according to its specification and throws a
> NumberFormatException when a conforming implementation of
In many cases, it is a good idea to first use the trim() method to the
String to be parsed.
int number;
String s = getStringToBeParsed(); // whatever you do to get the input
if (s != null) {
number = Integer.parseInt(s.trim());
} else {
// what ever is the proper thing to do in the particular case
}
--
Jukka Lahtinen
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Integer.parseInt() and whitespace? galt_57@hotmail.com - 2015-04-04 20:16 -0700 Re: Integer.parseInt() and whitespace? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2015-04-05 14:29 +0300 Re: Integer.parseInt() and whitespace? Arne Vajhøj <arne@vajhoej.dk> - 2015-04-05 13:22 -0400
csiph-web