dropLast

Common
JVM
JS
Native
1.0
fun CharSequence.dropLast(n: Int): CharSequence

Returns a subsequence of this char sequence with the last n characters removed.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val string = "<<<First Grade>>>"
println(string.drop(6)) // st Grade>>>
println(string.dropLast(6)) // <<<First Gr
println(string.dropWhile { !it.isLetter() }) // First Grade>>>
println(string.dropLastWhile { !it.isLetter() }) // <<<First Grade
//sampleEnd
}

Exceptions

IllegalArgumentException - if n is negative.

Common
JVM
JS
Native
1.0
fun String.dropLast(n: Int): String

Returns a string with the last n characters removed.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val string = "<<<First Grade>>>"
println(string.drop(6)) // st Grade>>>
println(string.dropLast(6)) // <<<First Gr
println(string.dropWhile { !it.isLetter() }) // First Grade>>>
println(string.dropLastWhile { !it.isLetter() }) // <<<First Grade
//sampleEnd
}

Exceptions

IllegalArgumentException - if n is negative.