Subject: Parse integer out of string 2005-07-07 - By Frans Verhoef
Back Actually not J2EE, but here we go:
String yourString = "A string that contains number 30 that needs to be parsed out"; Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(yourString); if(m.find()){ int yourInt = Integer.parseInt(yourString.substring(m.start(), m.end())); }
Cheers Frans
On Fri, 8 Jul 2005 10:26:10 +1000, Taco wrote: >?No just one. > >?I found java.util.regex.Matcher but a little help would be nice, >?I'm just a java newbie! > >?-- --Original Message-- -- >?From: A mailing list for Java(tm) 2 Platform, Enterprise Edition >?[mailto:J2EE-INTEREST@(protected)] On Behalf Of Mark Galbreath >?Sent: Friday, 8 July 2005 10:26 AM To: J2EE-INTEREST@(protected) >?Subject: Re: Parse integer out of string > >?Do you have multiple integer tokens, like > >?BDAT 30 LAST BDAT 30 LAST > >?? > >?~mark > >?Taco Fleur wrote: > >>?How do I parse an integer out of a string, for example: BDAT 30 >>?LAST >> >> >>?I did not find any regex support under the String class except >>?for matching. >> >> >>?__ ____ ____ ____ ____ ____ ____ >> >>?Taco Fleur - /E-commerce Development Manager/ >> >>?Shelco Searches &?Services >> >>?An Authorised ASIC Information Broker >> >>?www.shelco.com.au >> >>?Ph: + 61 7 3236 2605 >> >> >?=====================================================================>?====> >>?To unsubscribe, send email to listserv@(protected) and include >>?in the body of the message "signoff J2EE-INTEREST". For general >>?help, send email to listserv@(protected) and include in the body >>?of the message "help". >> >> >?=====================================================================>?===== To unsubscribe, send email to listserv@(protected) and >?include in the body of the message "signoff J2EE-INTEREST". ?For >?general help, send email to listserv@(protected) and include in >?the body of the message "help". > >?=====================================================================>?===== To unsubscribe, send email to listserv@(protected) and >?include in the body of the message "signoff J2EE-INTEREST". ?For >?general help, send email to listserv@(protected) and include in >?the body of the message "help".
==========================================================================To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|