How to extract single int digits from a String

Discussion in 'Java' started by loris_p, Jun 6, 2007.

  1. loris_p

    loris_p Guest

    Hi, I have a String containing numeric characters. I need to cycle on
    this String extracting one int digit per-cycle.
    Which method should I use?
    Thanks.
     
    loris_p, Jun 6, 2007
    #1
    1. Advertising

  2. Andrew Thompson, Jun 6, 2007
    #2
    1. Advertising

  3. loris_p

    loris_p Guest

    Thank you very much :)
     
    loris_p, Jun 6, 2007
    #3
  4. loris_p

    Roedy Green Guest

    On Wed, 06 Jun 2007 05:53:38 -0700, loris_p <>
    wrote, quoted or indirectly quoted someone who said :

    >Hi, I have a String containing numeric characters. I need to cycle on
    >this String extracting one int digit per-cycle.
    >Which method should I use?


    a loop with string.charAt() gets you each char.

    the fastest way to convert it to an int is to subtract '0'.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 15, 2007
    #4
    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. mark
    Replies:
    1
    Views:
    543
    Victor Bazarov
    Jun 14, 2004
  2. Schnoffos
    Replies:
    2
    Views:
    1,251
    Martien Verbruggen
    Jun 27, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,709
    Old Wolf
    Jan 20, 2004
  4. Replies:
    9
    Views:
    724
    Scott McPhillips [MVP]
    Nov 1, 2006
  5. lolveley
    Replies:
    2
    Views:
    112
    7stud --
    Apr 30, 2009
Loading...

Share This Page