split - Splitting String in scala ignores void fields at the end -


i'm scala beginer, , i'm facing issue :

from : "abcd ; efgh ; ijkl ; ; ; ; "

i have : array["abcd ","efgh "," ijkl " , "", "" , "" ,""]

while split function returns : ["abcd ","efgh "," ijkl " ]

could please ?

thanks in advance!

this behaviour comes java method split(regex). if want keep trailing empty strings in returned array must use overloaded method split(regex, limit):

scala> "a,b,c,,".split(",") res0: array[string] = array(a, b, c)  scala> "a,b,c,,".split(",", -1) res1: array[string] = array(a, b, c, "", "") 

note string given in example works because added spaces between separators:

scala> "a , b , c , , ".split(",") res2: array[string] = array("a ", " b ", " c ", " ", " ") 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -