Results 1 to 2 of 2
  1. #1
    larrifari is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default Scanner.delimiter - how to get commas and full-stops back?

    Hi, I am new to Java and am having a problem with a scanner I am using.

    I managed to tokenize my input and scan it for integers via scanner.hasNextInt(). First I had a problem with i.e. commas after numbers, they were not recognized but I fixed this by using a useDelimiter(", *);

    Now I have two new problems.

    a) How do i set my useDelimiter to commas, fullstops, question marks at the same time?

    b) The comma delimiter is now removed, I would like it back after I have done what I needed to do with the Integer, how do I do this? I tried something like !isWhitespace but I dont know where the char is within my string to do this?


  2. #2
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    First of all, unless you want the delimiters to count as tokens, the use of regular expressions is much better (split() method). When you make a new StringTokenizer(" ");, every character between " and " counts as a seperate delimiter, so
    StringTokenizer st = new StringTokenizer(" ,./?!@#$%^&*()|;\"");
    for example, each character counts as a delimiter. Hope that helped.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

Similar Threads

  1. Getting rid of commas in large numbers?
    By wwuster in forum Advanced Java
    Replies: 12
    Last Post: 03-05-2012, 10:35 AM
  2. Use of Scanner class and Delimiter
    By tjhodge in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 05:26 PM
  3. Stops when opening ObjectInputStream
    By Norberhuis in forum Networking
    Replies: 4
    Last Post: 01-09-2009, 04:19 PM
  4. delimiter
    By satin in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 10:50 PM
  5. Bouncing Ball Just Suddenly Stops Mid Bounce
    By adlb1300 in forum Java 2D
    Replies: 1
    Last Post: 12-03-2007, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts