trimEnd

Returns a subsequence of this char sequence having trailing characters matching the predicate removed.

inline fun CharSequence.trimEnd(predicate: (Char) -> Boolean): CharSequence(source)
val text = "Hello, world!!!"
val trimmed = text.trimEnd { it == '!' }
println(trimmed)   // prints: Hello, world

Source