common Prefix With
Версия Kotlin: 1.0
fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolean = false): String
Возвращает самую длинную строку prefix, такую что эта последовательность символов и последовательность символов other начинаются с этого префикса, не разделяя суррогатные пары. Если у этой последовательности и other нет общего префикса, возвращает пустую строку.
Параметры
ignore Case
true для игнорирования регистра символов при сравнении. По умолчанию false.
Примеры
import kotlin.test.*
fun main() {
//sampleStart
println("Hot_Coffee".commonPrefixWith("Hot_cocoa")) // Hot_
println("Hot_Coffee".commonPrefixWith("Hot_cocoa", true)) // Hot_Co
println("Hot_Coffee".commonPrefixWith("Iced_Coffee")) //
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/common-prefix-with.html