takeWhile

Returns a subsequence of this char sequence containing the first characters that satisfy the given predicate.

inline fun CharSequence.takeWhile(predicate: (Char) -> Boolean): CharSequence(source)
fun main() {
    val str = "abc123xyz"
    val letters = str.takeWhile { it.isLetter() }
    println(letters)  // prints: abc
}

Source