Re: StringTokenizer Help

Discussion in 'Java' started by Phil Hanna, Jul 1, 2003.

  1. Phil Hanna

    Phil Hanna Guest

    On 24 Jun 2003 07:33:47 +0200, Tor Iver Wilhelmsen
    <> wrote:

    > (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
     
    Phil Hanna, Jul 1, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ARMANDO  PADILLA

    StringTokenizer help

    ARMANDO PADILLA, Jul 4, 2003, in forum: Java
    Replies:
    3
    Views:
    633
    Chris Smith
    Jul 4, 2003
  2. Liang Yew
    Replies:
    3
    Views:
    663
    Jacob
    Jul 21, 2003
  3. Jim Crowell

    StringTokenizer Question?

    Jim Crowell, Aug 20, 2003, in forum: Java
    Replies:
    9
    Views:
    3,827
    Roedy Green
    Aug 23, 2003
  4. ros
    Replies:
    2
    Views:
    478
  5. ronron10

    Help with java StringTokenizer

    ronron10, Dec 18, 2008, in forum: Java
    Replies:
    0
    Views:
    433
    ronron10
    Dec 18, 2008
Loading...

Share This Page