commonPrefixWith
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
fun CharSequence.commonPrefixWith( other: CharSequence, ignoreCase: Boolean = false ): String
Возвращает самую длинную строку prefix, такую что текущая последовательность символов и other последовательность символов начинаются с этого префикса, учитывая при этом парные суррогаты. Если у текущей и other нет общего префикса, возвращает пустую строку.
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–2020 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