To remove the first character of a string in Kotlin, you can use the substring method starting from index 1.
In this example,
str1
with a value of "Hello World"
.substring
method starting from index 1 to remove the first character.fun main(args: Array<String>) {
var str1 = "Hello World"
str1 = str1.substring(1)
println("Modified string is: $str1")
}
Modified string is: ello World
In this example,
str2
with a value of "apple"
.substring
method starting from index 1 to remove the first character.fun main(args: Array<String>) {
var str2 = "apple"
str2 = str2.substring(1)
println("Modified string is: $str2")
}
Modified string is: pple
In this tutorial, we learned How to Remove First Character in a String in Kotlin language with well detailed examples.