snippetjavaCritical
In Java, how do I check if a string contains a substring (ignoring case)?
Viewed 0 times
ignoringhowjavachecksubstringstringcasecontains
Problem
I have two
Strings, str1 and str2. How do I check if str2 is contained within str1, ignoring case?Solution
str1.toUpperCase().contains(str2.toUpperCase())UPD:
Original answer was using
toLowerCase() method. But as some people correctly noticed, there are some exceptions in Unicode and it's better to use toUpperCase(). Because:There are languages knowing more than one lower case variant for one upper case variant.
Code Snippets
str1.toUpperCase().contains(str2.toUpperCase())Context
Stack Overflow Q#2275004, score: 1096
Revisions (0)
No revisions yet.