Search code examples
stringkotlin

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


Example:

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

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


Solution

  • 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)