String contains - ignore case

AlwaysALearner picture AlwaysALearner · Dec 24, 2012 · Viewed 326k times · Source

Is it possible to determine if a String str1="ABCDEFGHIJKLMNOP" contains a string pattern strptrn="gHi"? I wanted to know if that's possible when the characters are case insensitive. If so, how?

Answer

PeterMmm picture PeterMmm · Dec 24, 2012

If you won't go with regex:

"ABCDEFGHIJKLMNOP".toLowerCase().contains("gHi".toLowerCase())