Scala shared-string separation: no missing blank lines?

I have a data file in csv format. I am trying to split each row using the basic split command. line.split(',') But when I get a string like this "2,,", instead of returning an array in such a way that Array(2,"","") I just get Array: Array(2). I definitely missed something basic, can anyone help to indicate the correct way to separate the comma here?

+4
source share
1 answer

It inherits from Java. You can achieve the desired behavior with overload split(String regex, int limit):

"2,,".split(",", -1) // = Array(2, "", "")

Pay attention to Stringinstead Char.

Java-, limit :

, , , . n , n - 1 , n . n , , . n , , , .

split(separator: Char) , limit .

+8

Source: https://habr.com/ru/post/1544993/


All Articles