Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Parse integer out of string

Duc Vo

2005-07-07


Properly this link would help you a little
http://www.catb.org/%7Eesr/faqs/smart-questions.html

-----Original Message-----
From: Taco [mailto:taco@(protected)]
Sent: Friday, 8 July 2005 12:14 PM
To: Duc Vo
Subject: RE: Parse integer out of string


Are all you Java developers so uptight?

Get a freaking life.. Ever heard of newbies?

-----Original Message-----
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@(protected)
Sent: Friday, 8 July 2005 12:05 PM
To: J2EE-INTEREST@(protected)
Subject: Re: Parse integer out of string

You should do your homework, mate. Should not ask question like that ...

Read documentation on Pattern and pattern grouping should help.

-----Original Message-----
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@(protected)
Sent: Friday, 8 July 2005 11:51 AM
To: J2EE-INTEREST@(protected)
Subject: Re: Parse integer out of string

I realize that. My point is it doesn't work..

See example that I included, and you will see it should have worked but
did
not, hence the error.

-----Original Message-----
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@(protected)
Sent: Friday, 8 July 2005 11:51 AM
To: J2EE-INTEREST@(protected)
Subject: Re: Parse integer out of string

Just make sure that you define yourInt outside the if statement.
To be more precise:

int yourInt;
if(m.find()){
   int yourInt =
Integer.parseInt(yourString.substring(m.start(),m.end()));
}else{
   // take your action in case no integer found in yourString
}

On Fri, 8 Jul 2005 11:21:22 +1000, Taco wrote:
> Thanks that's sort of what I put together as well.
>
> Using your example:
>
> 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())); }
> System.out.println("result: " + yourInt);
>
> I got:
>
> java.lang.Error: Unresolved compilation problem:
> yourInt cannot be resolved
>
> at SSLTransportLayer08.getResponse(SSLTransportLayer08.java:149) at
> SSLTransportLayer08.main(SSLTransportLayer08.java:74)
>
> Which means it never found anything.. ???
> I'm puzzled..
>
> -----Original Message-----
> From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
> [mailto:J2EE-INTEREST@(protected)
> Sent: Friday, 8 July 2005 11:18 AM To: J2EE-INTEREST@(protected)
> Subject: Re: Parse integer out of string
>
> 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
>
> ======================================================================
> ===== To unsubscribe, send email to listserv@(protected)
> include in the body of the message "signoff J2EE-INTEREST". For
> general help, send email to listserv@(protected)
> the body of the message "help".

========================================================================
===
To unsubscribe, send email to listserv@(protected)
body
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".

========================================================================
===
To unsubscribe, send email to listserv@(protected)
body
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".

========================================================================
===
To unsubscribe, send email to listserv@(protected)
body
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.