Added samples for String.replace() function
This commit is contained in:
committed by
Abduqodiri Qurbonzoda
parent
77180a5b13
commit
ee952db1a2
@@ -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.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user