commonPrefixWith
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.commonPrefixWith( other: CharSequence, ignoreCase: Boolean = false ): String
Возвращает самую длинную строку prefix такую, что эта последовательность символов и other последовательность символов начинаются с этого префикса, избегая разделения пар суррогатов. Если у этой и other нет общего префикса, возвращает пустую строку.
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
println("Hot_Coffee".commonPrefixWith("Hot_cocoa")) // Hot_
println("Hot_Coffee".commonPrefixWith("Hot_cocoa", true)) // Hot_Co
println("Hot_Coffee".commonPrefixWith("Iced_Coffee")) //
//sampleEnd
}Параметры
ignoreCase - true для игнорирования регистра символов при сопоставлении. По умолчанию false.
© 2010–2022 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/common-prefix-with.html