takeLastWhile

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

Since Kotlin

1.0

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val string = "<<<First Grade>>>"
println(string.take(8)) // <<<First
println(string.takeLast(8)) // Grade>>>
println(string.takeWhile { !it.isLetter() }) // <<<
println(string.takeLastWhile { !it.isLetter() }) // >>> 
   //sampleEnd
}

inline fun String.takeLastWhile(predicate: (Char) -> Boolean): String(source)

Returns a string containing last characters that satisfy the given predicate.

Since Kotlin

1.0

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val string = "<<<First Grade>>>"
println(string.take(8)) // <<<First
println(string.takeLast(8)) // Grade>>>
println(string.takeWhile { !it.isLetter() }) // <<<
println(string.takeLastWhile { !it.isLetter() }) // >>> 
   //sampleEnd
}