string - Scala StringLike split method creates extra double quotes for leading spaces -


i tried simple split csv styled string, contains spaces after commas this:

scala> """"first", "secondafterspace"""".split(",") res0: array[string] = array("first", " "secondafterspace"")  scala> res0(0) res3: string = "first"  scala> res0(1) res4: string = " "secondafterspace"" 

the second string of result array has unexpected double quotes, more original string has.

it ok contains additional space in beginning did not yet trim it. expect similar result in following additional leading space, instead of double quotes:

scala> """"first","secondnospace"""".split(",") res1: array[string] = array("first", "secondnospace") 

i know can workaround issue following, i'd understand if wrong or if bug:

scala> """"first", "secondafterspacetrimmed"""".split(",").map(_.trim) res2: array[string] = array("first", "secondafterspacetrimmed") 

just sure tried variants like

.split(',') .split(""",""") .split("""\,""") .split(array(',')) 

but same result of double quotes.

in context: scala-doc see method in stringlike used. documentation talks char array. yet can use regex, not documented, made me suspicious if using split method in java string... confused...

no, not. way repl represents it:

scala> val xs = """"first", "secondafterspace"""".split(",") xs: array[string] = array("first", " "secondafterspace"")  scala> xs.last res0: string = " "secondafterspace""  scala> xs.last.count(_ == '"') res1: int = 2 

as can see, there no quotes

to trim spaces after quote may use regexp in split:

scala> val xs = """"first", "secondafterspace"""".split(",[ ]?") xs: array[string] = array("first", "secondafterspace") 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -