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
  • 59,842
  • 6
  • 106
  • 166
Mikey Chen
  • 2,370
  • 1
  • 19
  • 31
  • 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

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

This would set the delimiter as the newline.

Simba
  • 1,641
  • 1
  • 11
  • 16