2

I am working with strings encoding tables of data:

var table =
"""1 2 3
4 5 6
7 8 9"""

I can see that in the Scala worksheet this is evaluated to:

table: String =
1 2 3 //1
4 5 6 //2
7 8 9

When I try to split the values by newline and space characters:

table.split("\n").map(_.split("\\s+"))

The extra characters are present:

res25: Array[Array[String]] = Array(Array(1, 2, 3, //1), Array(4, 5, 6, //2), Array(7, 8, 9))

What is the reason of those characters being there?

Krzysztof Słowiński
  • 6,239
  • 8
  • 44
  • 62
  • 1
    A wild guess, but is the file written using `\r\n` new line encoding or with some other invisible symbol there? When I tested it in REPL I got a correct result (3 x 3 nested Arrays). – Mateusz Kubuszok Aug 15 '19 at 13:15
  • I am using IntelliJ on Mac and it is working fine in REPL for me as well. Just wondering why is there a difference when using a worksheet. – Krzysztof Słowiński Aug 15 '19 at 13:50

0 Answers0