dropLast

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

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

import java.util.Locale
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
(source)

Returns a string with the last n characters removed.

import java.util.Locale
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.