Kotlin .drop()
Published Nov 6, 2023
Contribute to Docs
The .drop() method removes characters from the start (0th index) of a given string to the nth index element.
Syntax
String.drop(nth-index)
String: The string to be modified. The method will return a new string with the specified values missing.nth-index: The method will remove characters up to this value.
Example
The example demonstrates the use of .drop() to remove characters from the beginning of the string.
fun main() {val str = "This is new"val str2 = "I'm a string"println(str.drop(8)) // Drops 'This is 'println(str2.drop(6)) // Drops 'I'm a '}
The output of the code above will be:
newstring
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours