![]() |
Re: StringTokenizer Help
On 24 Jun 2003 07:33:47 +0200, Tor Iver Wilhelmsen
<tor.iver.wilhelmsen@broadpark.no> wrote: >tannisd@yahoo.com (T. Drysdale) writes: > >> I can use the StringTokenizer to parse based on spaces or special >> characters, but for the life of me can't figure out how to get the >> class name out! >> >> Any suggestions??? > >Yes, use regexps instead (either 1.4's builtin support or one of the >libraries for older versions). As an illustration of what Tor is describing: import java.io.*; import java.net.*; import java.util.*; import java.util.regex.*; public class ClassNameParser { public static void main(String[] args) throws IOException { String fileName = args[0]; Pattern p = Pattern.compile ("\\Wnew\\s+([_a-zA-Z][_a-zA-Z0-9]*)"); BufferedReader in = new BufferedReader( new FileReader(fileName)); while (true) { String line = in.readLine(); if (line == null) break; Matcher m = p.matcher(line); while (m.find()) { String className = m.group(1); System.out.println(className); } } } } -- Phil Hanna Author of JSP 2.0: The Complete Reference http://www.philhanna.com http://www.philhanna.com |
| All times are GMT. The time now is 08:15 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.