如何在Kotlin中检查字符串是否包含子字符串? [英] How to check whether a string contains a substring in Kotlin?
本文介绍了如何在Kotlin中检查字符串是否包含子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
String1 = "AbBaCca";
String2 = "bac";
我要检查String1是否包含String2.
I want to perform a check that String1 contains String2 or not.
推荐答案
Kotlin具有stdlib
包,可以对字符串执行某些扩展功能操作,可以选中此方法,它将检查字符串中的子字符串,可以忽略通过传递true/false值的情况.引用此链接
Kotlin has stdlib
package to perform certain extension function operation over the string, you can check this method it will check the substring in a string, you can ignore the case by passing true/false value. Refer this link
"AbBaCca".contains("bac", ignoreCase = true)
这篇关于如何在Kotlin中检查字符串是否包含子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文