JetBrains / kotlin-playground

Self-contained component to embed in websites for running Kotlin code
https://jetbrains.github.io/kotlin-playground/examples/
Apache License 2.0
447 stars 80 forks source link

String.substringAfter(String) behaves incorrectly #204

Open markoteittinen opened 5 months ago

markoteittinen commented 5 months ago

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"