SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to remove non-numeric data

    Hi,

    This is bugging me BIG style!

    I need to be ble to import an XML document. One of the elements contains data relating to the school year a student is in. Unfortunately, the source of this data is not clean and so a student in year 7 could have "Y7", "y7", "7", "Year 7","year7".......

    How can I simply strip all the non-numeric characters from the string to be left with (ultimately an int) of "7"?

    TIA

    Paul
    Paul Simpson, BSc, MCNI, MCNE

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    int year = Integer.parseInt( "Year 7".replaceAll( "\\D", "" ) );

    // year == 7

    \D means any non-digit character

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Thanks, as always rushiku!

    Paul Simpson, BSc, MCNI, MCNE


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •