W3cubDocs

/Kotlin

replace

Platform and version requirements: JVM (1.0), JS (1.1)
fun String.replace(
    oldChar: Char, 
    newChar: Char, 
    ignoreCase: Boolean = false
): String
Platform and version requirements: Native (1.3)
fun String.replace(
    oldChar: Char, 
    newChar: Char, 
    ignoreCase: Boolean
): String

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

Platform and version requirements: JVM (1.0), JS (1.1)
fun String.replace(
    oldValue: String, 
    newValue: String, 
    ignoreCase: Boolean = false
): String
Platform and version requirements: Native (1.3)
fun String.replace(
    oldValue: String, 
    newValue: String, 
    ignoreCase: Boolean
): String

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

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.replace(
    regex: Regex, 
    replacement: String
): String

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.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
inline fun CharSequence.replace(
    regex: Regex, 
    noinline transform: (MatchResult) -> CharSequence
): String

Returns 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.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/replace.html