This page is no longer maintained — Please continue to the home page at www.scala-lang.org

String.split bug, confirmed by Antonio Cunei

1 reply
Glenn
Joined: 2011-11-15,
User offline. Last seen 42 years 45 weeks ago.

Using scala-2.9.1-final:
scala> ":yo:howdy:::".split(":")
res7: Array[java.lang.String] = Array("", yo, howdy)

scala> ":yo:howdy::: ".split(":")
res8: Array[java.lang.String] = Array("", yo, howdy, "", "", " ")

I expected res7 to be: Array("", yo, howdy, "", "", "")

Thanks.

Bakos Gábor
Joined: 2009-06-08,
User offline. Last seen 42 years 45 weeks ago.
Re: String.split bug, confirmed by Antonio Cunei

On 2011.11.15. 18:08, Glenn wrote:
> Using scala-2.9.1-final:
> scala> ":yo:howdy:::".split(":")
> res7: Array[java.lang.String] = Array("", yo, howdy)
>
> scala> ":yo:howdy::: ".split(":")
> res8: Array[java.lang.String] = Array("", yo, howdy, "", "", " ")
>
> I expected res7 to be: Array("", yo, howdy, "", "", "")
Hi Glenn,

You should not:
http://download.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)
This is what you might want to check:
http://download.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String,
int) with negative second parameter.
Hope this helps, gabor

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland