How do I use the useDelimiter()
method of the Scanner
class to use both the comma (,) and the new line character (\n) as delimiters?
I am parsing some text from a csv file.
Scanner s = new Scanner("hello, world \n hello world");
s.useDelimiter(",|\\n");
while(s.hasNext()){
System.out.println(s.next());
}
Output
hello
world
hello world
How about useDelimiter(",|\\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With