Hi there,

It's been a long time since I've used delimiters in the Scanner class in Java. If I wanted to have any numbers between an expression, such as xx/xx/xxxx or an infinite amount of numbers between them with just the forward slashes as delimiters, what would the syntax be? I came up with

s.useDelimiter(".*/.*/.*")

And is this similar to C++ and Python? Also can't remember. D'oh! Sorry, and thanks for your help!

I don't know why I'm rewarding your laziness like this, but here's the code you could have / should have written for yourself in less time than it took to write that post

String input = "12/345/6789";
      Scanner s = new Scanner(input).useDelimiter("/");
      System.out.println(s.nextInt());
      System.out.println(s.nextInt());
      System.out.println(s.nextInt());

All right, well, ignoring the sarcasm, I've tried that as well as other combinations. If I have a text file that is separated as such:

12/32/4323
31/13/23
...

This throws an InputMismatchException because of the whitespace, so isn't it * or .* to fix that and the new lines? Thanks for the help.

That's not the same format as the data in the first post, so onviously the answer is going to be different.
Are you saying there may also be arbitrary white space in the data? Or only inbetween numbers? As well as or instead of the / demiliters?

Assuming they are not embedded then you need to delimlit on any number of white spaces and/or / characters.
You could try useDelimiter("[\\s/]*"
... but there are others here who are for moreexpert in regexs than I am.

Edited 4 Years Ago by JamesCherrill: n/a

Maybe this:
For a delimiter of one or more white space chars OR a "/"
useDelimiter("\\s+|/")

Edited 4 Years Ago by JamesCherrill: Fixed

This question has already been answered. Start a new discussion instead.