KT-20357: Add samples for indexOf
This commit is contained in:
committed by
Ilya Gorbunov
parent
a6f829f267
commit
e30d87ee01
@@ -204,6 +204,7 @@ class Strings {
|
|||||||
val noPadding = "abcde".padEnd(3)
|
val noPadding = "abcde".padEnd(3)
|
||||||
assertPrints("'$noPadding'", "'abcde'")
|
assertPrints("'$noPadding'", "'abcde'")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sample
|
@Sample
|
||||||
fun clearStringBuilder() {
|
fun clearStringBuilder() {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
@@ -357,4 +358,15 @@ class Strings {
|
|||||||
assertPrints(string.map { it.toUpperCase() }, "[K, O, T, L, I, N]")
|
assertPrints(string.map { it.toUpperCase() }, "[K, O, T, L, I, N]")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sample
|
||||||
|
fun indexOf() {
|
||||||
|
fun getSubstringDetails(str: String, toFind: String): String {
|
||||||
|
return "Found $toFind in $str at position ${str.indexOf(toFind)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
val str = "Kotlin"
|
||||||
|
val toFind = "otli"
|
||||||
|
|
||||||
|
assertPrints(getSubstringDetails(str, toFind), "Found otli in Kotlin at position 1")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -984,6 +984,7 @@ public fun CharSequence.lastIndexOfAny(strings: Collection<String>, startIndex:
|
|||||||
*
|
*
|
||||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||||
* @return An index of the first occurrence of [char] or -1 if none is found.
|
* @return An index of the first occurrence of [char] or -1 if none is found.
|
||||||
|
* @sample samples.text.Strings.indexOf
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
public fun CharSequence.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||||
return if (ignoreCase || this !is String)
|
return if (ignoreCase || this !is String)
|
||||||
@@ -998,6 +999,7 @@ public fun CharSequence.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boo
|
|||||||
*
|
*
|
||||||
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
* @param ignoreCase `true` to ignore character case when matching a string. By default `false`.
|
||||||
* @return An index of the first occurrence of [string] or `-1` if none is found.
|
* @return An index of the first occurrence of [string] or `-1` if none is found.
|
||||||
|
* @sample samples.text.Strings.indexOf
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
public fun CharSequence.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||||
return if (ignoreCase || this !is String)
|
return if (ignoreCase || this !is String)
|
||||||
|
|||||||
Reference in New Issue
Block a user