W3cubDocs

/Kotlin

drop

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.drop(n: Int): CharSequence

Returns a subsequence of this char sequence with the first 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.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun String.drop(n: Int): String

Returns a string with the first 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.

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/drop.html