SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: How to remove non-numeric data
-
Oct 6, 2006, 07:46 #1
- 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
PaulPaul Simpson, BSc, MCNI, MCNE
-
Oct 6, 2006, 08:34 #2
- 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
-
Oct 6, 2006, 13:26 #3
- Join Date
- Dec 2001
- Location
- Market Harborough, UK
- Posts
- 206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, as always rushiku!
Paul Simpson, BSc, MCNI, MCNE
Bookmarks