0

Assuming I have two lines of text like this:

sam|y|rutgers
jane|y|penn state

My current scanner would report:

sam|y|rutgers
jane|y|penn
state

instead of keeping the penn state together.

Is there any way I can specify the delimeter settings to include the new line, but not a space?

Boris the Spider
  • 54,398
  • 6
  • 98
  • 152
hendersawn
  • 2,110
  • 1
  • 13
  • 29
  • 1
    `Scanner` has a [`useDelimiter`](https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#useDelimiter(java.util.regex.Pattern)) method. It also has a [`nextLine`](https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextLine()) method. In short, read [the documentation](https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html). – Boris the Spider Dec 01 '14 at 22:14

1 Answers1

1
Scanner scan = new Scanner(...);
String val = scan.nextLine();

This would set the delimiter as the newline.

Simba
  • 1,533
  • 9
  • 16