kotlin-playground icon indicating copy to clipboard operation
kotlin-playground copied to clipboard

String.substringAfter(String) behaves incorrectly

Open markoteittinen opened this issue 1 year ago • 0 comments

The following simple program shows incorrect result on Kotlin Playground:

val str = "This is not that long a string"

fun main() {
    val part = str.substringAfter("is ").substringBefore(" long")
    println("Full: $str")
    println("Part: $part")
}

Obviously, it should display "not that", but instead it displays "is not that". It seems that substringAfter() includes the delimiter string "is " parameter in its return value, but it should not.

When I run the same code on Android (i.e. JVM), the result is correctly "not that"

markoteittinen avatar Mar 27 '24 23:03 markoteittinen