To get a substring from a specific index to the end in Kotlin, you can use the `substring` method of the String class.
In this example,
str
with a value of "Hello World"
.substring
method with the starting index 5
to get the substring from that index to the end of the string.fun main() {
val str = "Hello World"
val substring = str.substring(5)
println("Substring from index 5 to end: $substring")
}
Substring from index 5 to end: World
In this example,
text
with a value of "Kotlin Programming"
.substring
method with the starting index 3
to get the substring from that index to the end of the string.fun main() {
val text = "Kotlin Programming"
val substring = text.substring(3)
println("Substring from index 3 to end: $substring")
}
Substring from index 3 to end: lin Programming
In this tutorial, we learned How to get Substring from Specific Index to End in Kotlin language with well detailed examples.