Q:

Check if piece of String is there in string java

i am looking for a piece of code which can search for a string in a string.
String mainSTR = "It is Wednesday";

So i need a code that will return true if i search
"Day" or "day" or "DAY"  in mainSTR.
I tried methods like
mainSTR.contains("")

and
mainSTR.IndexOf("") > -1

are not working for me
Thanks :)

A:

If mainSTR is a really long String, this approach may be more efficient:
String mainSTR = "It is Wednesday";
String toSearch = "Day";
boolean found = Pattern.compile(toSearch, Pattern.CASE_INSENSITIVE).matcher(mainSTR).find();

the last line is equivalent to
boolean found = Pattern.compile("(?i)" + toSearch).matcher(mainSTR).find();

But beware that toSearch may not contain regex meta characters if you do it this way.

