Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #834
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Wed, 06 Jul 2011 18:53:40 -0500 |
| Date | Wed, 06 Jul 2011 16:53:39 -0700 |
| From | Patricia Shanahan <pats@acm.org> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? |
| References | <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> <iulrmk$sg9$1@dont-email.me> <k4b6175jsqa1kie5u7b7pjed29td61lkf1@4ax.com> <iuvi8e$m6g$1@dont-email.me> <7an6179km7upsvba40ebe98gmfedg2414k@4ax.com> <iuvqj8$ilj$1@dont-email.me> <dss6179oa9vq21vf7tlu6e78bdhqjdm65m@4ax.com> <iv01d2$2g5$1@dont-email.me> <vf891713vu8quck6170207ec1bv17700cf@4ax.com> <iv2b1s$27u$1@dont-email.me> <njl917lc1nft61r62721n5ihbd2mb26pam@4ax.com> <iv2o2d$lbu$1@dont-email.me> |
| In-Reply-To | <iv2o2d$lbu$1@dont-email.me> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Message-ID | <gZqdnXOFVegZaInTnZ2dnUVZ_r2dnZ2d@earthlink.com> (permalink) |
| Lines | 41 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 70.230.196.78 |
| X-Trace | sv3-tUfAbojRy37wONkIvuJOSZ7LtCpJNZXU73gtu6TMNxzqjS2kdg0inWphZwJNVE8CEzCyuFaTBOE8OQn!sh/N1rqz0LpKkSqVRABX6rfbOpxv+ZbLBGIVVNII9dMNnK9KvENzETUYuM2opr+6UvLGap/m1kHk!/lZtfHRf/VTZLBZvej9K5pOODBj80w3JF0uyhTxIc2FrRQ== |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3109 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:834 |
Show key headers only | View raw
On 7/6/2011 3:36 PM, markspace wrote: > On 7/6/2011 2:58 PM, Thee Chicago Wolf [MVP] wrote: > >> Well, I originally used int[] x = new int[str.length]; but it gives a >> compile error. (str.length()] does work though. Guessing because it's > > > Yup, I missed that one, it's length(). > > >> stuff that I used. Thanks for that tip! But does the - '0' portion of >> x[i] = str.charAt(i) - '0'; just tell it to convert to its ASCII >> value? We dicussed this here and were like WTF is this? What exactly >> is that portion doing? Thanks for walking me through it. > > > For ASCII values, UTF (what Java uses) and ASCII are the same values. > "char" is an integer already, there's no need to convert. str.charAt( x > ) already returns a number, just a number encoded to mean a UTF > character (code point?). > > So, you just have to map one number range to another. '0' is 48 decimal. > E.g.: > > '0' - '0' = 48 - 48 = 0. > '1' - '0' = 49 - 48 = 1. > '2' - '0' = 50 - 48 = 2. > > etc. Remember Neo in The Matrix? It's all just number, really, even the > letters. > Or, of course, you could use the Character.digit method. It's a bit more flexible, allowing a one line change e.g. to do hexadecimal instead of decimal, and providing easy internationalization. I realize these issues will probably not arise in this context, but in general it is better to learn to use API methods than to roll your own that deals with a subset of the cases. Patricia
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-01 12:53 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Jeff Higgins <jeff@invalid.invalid> - 2011-07-01 17:55 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-01 18:19 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:26 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 13:39 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 13:57 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 13:01 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 15:47 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 14:57 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:11 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 11:54 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 16:58 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 15:36 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-06 16:53 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 18:07 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-06 09:57 +0100
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:13 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-07 09:43 +0100
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:15 +0200
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:14 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 16:27 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:22 +0200
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-06 07:33 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-01 23:06 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-01 20:28 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:27 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Roedy Green <see_website@mindprod.com.invalid> - 2011-07-04 08:59 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:30 -0500
csiph-web