To replace a character at a specific index in a string in Kotlin, you can use string manipulation functions like `substring` and `plus`.
In this example,
str
.index
with the character newChar
using string manipulation.str
.fun main() {
var str = "Hello World"
val index = 6
val newChar = 'x'
str = str.substring(0, index) + newChar + str.substring(index + 1)
println(str)
}
Hello xorld
In this tutorial, we learned How to Replace Character at Specific Index in String in Kotlin language with well detailed examples.