Added samples for String.replace() function

This commit is contained in:
Kris Hall
2020-11-19 15:26:08 -06:00
committed by Abduqodiri Qurbonzoda
parent 77180a5b13
commit ee952db1a2
2 changed files with 13 additions and 0 deletions
@@ -196,12 +196,16 @@ public expect fun CharSequence.repeat(n: Int): String
/**
* Returns a new string with all occurrences of [oldChar] replaced with [newChar].
*
* @sample samples.text.Strings.replace
*/
expect fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String
/**
* Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string
* with the specified [newValue] string.
*
* @sample samples.text.Strings.replace
*/
expect fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String
@@ -445,4 +445,13 @@ class Strings {
assertPrints(emptyString.lastOrNull(), "null")
assertFails { emptyString.last() }
}
@Sample
fun replace() {
val inputString0 = "Mississippi"
val inputString1 = "Insufficient data for meaningful answer."
assertPrints(inputString0.replace('s', 'z'), "Mizzizzippi")
assertPrints(inputString1.replace("data", "information"), "Insufficient information for meaningful answer.")
}
}