Skip to content

String.substringAfter(String) behaves incorrectly #204

@markoteittinen

Description

@markoteittinen

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions