replace

actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String(source)

Returns a new string with all occurrences of oldChar replaced with newChar.

Since Kotlin

1.0

Samples



import java.util.Locale


import kotlin.test.*
fun main() { 
   //sampleStart 
   val inputString0 = "Mississippi"
val inputString1 = "Insufficient data for meaningful answer."

println(inputString0.replace('s', 'z')) // Mizzizzippi
println(inputString1.replace("data", "information")) // Insufficient information for meaningful answer. 
   //sampleEnd
}

actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String(source)

Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.

Since Kotlin

1.0

Samples



import java.util.Locale


import kotlin.test.*
fun main() { 
   //sampleStart 
   val inputString0 = "Mississippi"
val inputString1 = "Insufficient data for meaningful answer."

println(inputString0.replace('s', 'z')) // Mizzizzippi
println(inputString1.replace("data", "information")) // Insufficient information for meaningful answer. 
   //sampleEnd
}