String Manipulation

Discussion in 'Java' started by TheVooDooChild, Mar 25, 2005.

  1. I have an alpha-numeric string. If the 1st position is non-numeric, I
    need to remove it. For some reason this is causing me difficulty. Can
    someone show me a way to do this? Example: "R123456789" I want
    "123456789"

    Thanks.
     
    TheVooDooChild, Mar 25, 2005
    #1
    1. Advertising

  2. TheVooDooChild

    Fahd Shariff Guest

    String s = "R123456789" ;

    //get first char
    char c = s.charAt(0) ;

    //is it non-numeric?
    if(!Character.isDigit(c)){
    //remove it
    s = s.substring(1,s.length());
    }

    --
    Fahd Shariff
    http://www.fahdshariff.cjb.net
    "Let the code do the talking... "
     
    Fahd Shariff, Mar 25, 2005
    #2
    1. Advertising

  3. Thank you!
     
    TheVooDooChild, Mar 25, 2005
    #3
  4. TheVooDooChild

    Lisa Guest

    "Fahd Shariff" <> wrote in message
    news:...
    > String s = "R123456789" ;
    >
    > //get first char
    > char c = s.charAt(0) ;
    >
    > //is it non-numeric?
    > if(!Character.isDigit(c)){
    > //remove it
    > s = s.substring(1,s.length());
    > }
    >


    you can use "s = s.substring(1);"
    instead of specifying the length explicitly

    > --
    > Fahd Shariff
    > http://www.fahdshariff.cjb.net
    > "Let the code do the talking... "
    >
     
    Lisa, Mar 25, 2005
    #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. jared in ecs

    Perl string manipulation

    jared in ecs, Oct 22, 2003, in forum: Perl
    Replies:
    2
    Views:
    812
    Roy Johnson
    Oct 22, 2003
  2. Garfield

    String Array Manipulation Problem

    Garfield, Aug 27, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,817
    Michael Lang
    Aug 27, 2003
  3. Aaron

    String Manipulation

    Aaron, Dec 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    4,632
    Dave Davidson
    Dec 31, 2003
  4. Aaron

    Advanced String Manipulation (C#)

    Aaron, Jan 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    822
  5. Chris

    String manipulation

    Chris, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    452
    Pete Wright
    May 24, 2004
Loading...

Share This Page