Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Scanner delimiter

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Scanner delimiter

    Hi

    I have an assignment and i think the authors made a mistake because the scanner useDelimiter() method is not working

    Here is the delimiter
    "[\\s[^'a-zA-Z]]"

    So far Ive coded

    Scanner scan = new Scanner(aFileName); // aFileName is an argument in the method header
    scan.useDelimiter([\\s[^'a-zA-Z]]);
    ...
    ...
    While (scan.hasNext())
    {
    String aWord = scan.next()
    ...
    ... //add aWord to a hashMap for processing
    }

    My question is what does the code in the delimiter mean? and can it detect commas i.e (,) or full stops for that matter


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,514
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: Scanner delimiter

    The code is using a regular expression. Go to the Pattern class in the Java API or google "regex tutorial" for more information.
    Improving the world one idiot at a time!

Similar Threads

  1. use Delimiter, Scanner Class
    By izzahmed in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 25th, 2011, 05:27 PM
  2. Scanner help
    By sp11k3t3ht3rd in forum Java Theory & Questions
    Replies: 3
    Last Post: June 22nd, 2011, 11:55 AM
  3. [SOLVED] Problem with Scanner ?
    By derekeverett in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 19th, 2010, 04:34 AM
  4. delimiter question
    By Sterzerkmode in forum Java SE APIs
    Replies: 1
    Last Post: November 19th, 2009, 05:21 AM
  5. Help With Scanner
    By jtphenom in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 12th, 2009, 08:49 PM