To replace a substring in a string in Kotlin, you can use the `replace()` function.
In this example,
str
with a value of "Hello World"
.replace()
function to replace the substring "World"
with "Universe"
.str
.fun main(args: Array<String>) {
var str = "Hello World"
str = str.replace("World", "Universe")
println(str)
}
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in Kotlin language with well detailed examples.