Java Mailing List Archive

http://www.junlu.com/

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

Re: Parse integer out of string

Taco Fleur

2005-07-07

Replies:

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)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.