How to check whether a string contains a substring in Kotlin?

前端 未结 4 1690
死守一世寂寞
死守一世寂寞 2021-02-05 01:47

Example:

String1 = \"AbBaCca\";
String2 = \"bac\";

I want to perform a check that String1 contains String2 or not.

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 02:04

    Kotlin has a few different contains function on Strings, see here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/contains.html.

    If you want it to be true that string2 is contained in string1 (ie you want to ignore case), they even have a convenient boolean argument for you, so you won't need to convert to lowercase first.

提交回复
热议问题