Kotlin program to demonstrate the example of replace() function
// Example of replace() function
fun main()
{
// Demonstrating the replace() function
val pattern = Regex("Hi")
// Replace all "Hi" with "Hello"
println(pattern.replace("Hi, there.", "Hello"))
println(pattern.replace("Hi Alex! Please say Hi to Boss.", "Hello"))
println(pattern.replace("IncludeHelp", "Okay"))
println()
}
Output:
Hello, there.
Hello Alex! Please say Hello to Boss.
IncludeHelp
Kotlin program to demonstrate the example of replace() function
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer