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

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

    The most idiomatic way to check this is to use the in operator:

    String2 in String1
    

    This is equivalent to calling contains(), but shorter and more readable.

提交回复
热议问题