How to convert an alphanumerical String into one 'only numerical' where the charachters which are not [0-9] are removed?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mauro_fabrizioli
Posted On:   Monday, September 24, 2001 02:27 AM

I have to extract from a String only the sequence of the contained numerical characters, i.e. [0-9],
removing all the others. May I use some ready class or package?
Thank you

Re: How to convert an alphanumerical String into one 'only numerical' where the charachters which are not [0-9] are removed?

Posted By:   Anonymous  
Posted On:   Monday, September 24, 2001 05:48 AM

Hi,

Try this, it might help.



String s = "abc123" ;
char[] ch = s.toCharArray();
StringBuffer sb = new StringBuffer();

for(int i=0;i if(Character.isDigit(ch[i]))
sb.append(ch[i]);
}

int number = Integer.parseInt (sb.toString());



Hope it solves ur problem,


~vivek
About | Sitemap | Contact