faster2b
faster2b

Reputation: 672

Change Source.fromfile().getLines delimiter in Scala

I need to change the row delimiter in getLines method, actually default delimiter is ("\n" | "\r\n" | "\r") but I need only \n.

For example, in my string "xxxxx xxxxx \r xxxx xxx\n xxxxx xxxxx \r xxxx xxx" with getLines I obtain 3 lines, but i need only 2, is possible to change it?

thank you

Upvotes: 1

Views: 527

Answers (1)

Gabriele Petronella
Gabriele Petronella

Reputation: 108149

As the documentation suggests, you can refine the behavior of getLines by subclassing LineIterator.

class MyLineIterator extends LineIterator {
  override def isNewline(ch: Char) = ch == '\n'
}

Upvotes: 1

Related Questions