Following is my REPL output. I am not sure why string.split does not work here.
val s = "Pedro|groceries|apple|1.42"
s: java.lang.String = Pedro|groceries|apple|1.42
scala> s.split("|")
res27: Array[java.lang.String] = Array("", P, e, d, r, o, |, g, r, o, c, e, r, i, e, s, |, a, p, p, l, e, |, 1, ., 4, 2)
If you use quotes, you’re asking for a regular expression split.
|is the “or” character, so your regex matches nothing or nothing. So everything is split.If you use
split('|')orsplit("""\|""")you should get what you want.