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

前端 未结 4 1697
死守一世寂寞
死守一世寂寞 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:06

    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)
    

提交回复
热议问题