To append a character to the beginning of a string in Kotlin, you can use string interpolation or the plus operator.
In this example,
str1
with a value of "ello"
.'H'
to str1
.str1
.fun main() {
var str1 = "ello"
str1 = 'H' + str1
println(str1)
}
Hello
In this example,
str2
with a value of "orld"
.'W'
to str2
.str2
.fun main() {
var str2 = "orld"
str2 = 'W' + str2
println(str2)
}
World
In this tutorial, we learned How to Append a Character to beginning of a String in Kotlin language with well detailed examples.