replace
Returns a new string obtained by replacing each substring of this char sequence that matches the given regular expression with the given replacement.
The replacement can consist of any combination of literal text and $-substitutions. To treat the replacement string literally escape it with the kotlin.text.Regex.Companion.escapeReplacement method.
Since Kotlin
1.0Returns a new string obtained by replacing each substring of this char sequence that matches the given regular expression with the result of the given function transform that takes MatchResult and returns a string to be used as a replacement for that match.
Since Kotlin
1.0Returns a new string with all occurrences of oldChar replaced with newChar.
Since Kotlin
1.0Samples
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
}
Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.
Since Kotlin
1.0Samples
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
}
Returns a new string with all occurrences of oldChar replaced with newChar.
Since Kotlin
1.1Samples
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
}
Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.
Since Kotlin
1.1Samples
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
}
Returns a new string with all occurrences of oldChar replaced with newChar.
Since Kotlin
1.0Samples
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
}
Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.
Since Kotlin
1.0Samples
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
}
Returns a new string with all occurrences of oldChar replaced with newChar.
Since Kotlin
1.3Samples
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
}
Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.
Since Kotlin
1.3Samples
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
}