Artem
06/06/2018, 5:23 PMfun doStuff(input:String) {
val split = input.split("foo", 0)
}
will not compile, but this one:
fun doStuff(input:String) {
val split = java.lang.String(input).split("foo", 0)
}
will be OK. Is it supposed behaviour (in other words, is it a bug or is it a feature)?Andreas Sinz
06/06/2018, 5:29 PMkotlin.String.split
is not the same as java.lang.String.split
, they have different parametersilya.gorbunov
06/06/2018, 5:38 PMval split = input.split("foo", limit = 0)
.
Also mind that:
1) limit = 0
is the default value for limit
, so there's no need to specify it explicitly.
2) split("foo")
treats foo
delimiter as a literal rather than a regular expression.Artem
06/07/2018, 7:43 AMsplit
, and I found that behaviour of limit
is different with Java. Java doc says that If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
, however Kotlin implementation keeps trailing empty strings