Results 1 to 2 of 2
- 02-20-2009, 01:07 PM #1Member
- Join Date
- Feb 2009
- Rep Power
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?
- 02-20-2009, 02:06 PM #2
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.
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- By wwuster in forum Advanced JavaReplies: 12Last Post: 03-05-2012, 10:35 AM
- By tjhodge in forum New To JavaReplies: 3Last Post: 02-12-2009, 05:26 PM
- By Norberhuis in forum NetworkingReplies: 4Last Post: 01-09-2009, 04:19 PM
- By satin in forum New To JavaReplies: 2Last Post: 11-17-2008, 10:50 PM
- By adlb1300 in forum Java 2DReplies: 1Last Post: 12-03-2007, 02:58 PM