To remove the first N characters of a string in Kotlin, you can use the substring method starting from index N.
In this example,
str1
with a value of "Hello World"
.fun main() {
val str1 = "Hello World"
val result = str1.substring(3)
println("Modified string is: $result")
}
Modified string is: lo World
In this example,
str2
with a value of "apple"
.fun main() {
val str2 = "apple"
val result = str2.substring(2)
println("Modified string is: $result")
}
Modified string is: ple
In this tutorial, we learned How to Remove first N Characters in a String in Kotlin language with well detailed examples.