Kotlin commonSuffixWith用法及代码示例

本文方法及代码示例基于Kotlin 2.1.20 Released

commonSuffixWith 所在包 kotlin.text.commonSuffixWith,其相关用法介绍如下:

用法:

kotion 复制代码
fun CharSequence.commonSuffixWith(
    other: CharSequence, 
    ignoreCase: Boolean = false
): String

返回最长的字符串 suffix 使得这个 char 序列和 other char 序列都以此后缀结尾,注意不要拆分代理对。如果 this 和 other 没有共同的后缀,则返回空字符串。

代码示例:

kotlin 复制代码
import java.util.Locale
import kotlin.test.*

fun main(args: Array<String>) {
    //sampleStart
    println("Hot_Tea".commonSuffixWith("iced_tea")) // ea
    println("Hot_Tea".commonSuffixWith("iced_tea", true)) // _Tea
    println("Hot_Tea".commonSuffixWith("Hot_Coffee")) //
    //sampleEnd
}

// 输出
ea
_Tea

参数:ignoreCase-true匹配字符时忽略字符大小写。默认false.

相关方法

相关推荐
summerkissyou19879 小时前
Android - 摄像头 - hal - 开发教程,例子,常见问题,分析方法,解决方案
android
summerkissyou198710 小时前
Android 16 架构图
android
神龙天舞200110 小时前
MySQL 备库为什么会延迟好几个小时
android·数据库·mysql
码农coding13 小时前
android12 systemUI 之锁屏
android
圆山猫14 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
爱笑鱼14 小时前
Binder(七):getCallingUid() 读到的是谁?clearCallingIdentity() 又清掉了什么?
android
2501_9159090620 小时前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
Lvan的前端笔记20 小时前
AndroidX 完全入门指南
android·androidx
帅次20 小时前
Android 应用高级面试:Window 近1年高频追问 18 题
android·面试·职场和发展
总捣什么乱121 小时前
MySQL MySQL是怎么保证主备一致的?
android·mysql·adb