How to make index case insensitive in java

I have a simple question. How to make index case insensitive in java. This question has already been answered, but I did not understand the answer.

Say, for example, I have the line s = Phone (Conf) I want to pull an entry that has (Conf) like this, but users enter CONF or conf or Conf, etc. Therefore, my program should be able to pull out the entry if it finds the word conf anyway.

if(s.indexOf("(")>-1&& s.indexOf("Conf")>-4 && s.lastIndexOf(")")>-1) { String s1=s.substring(s.indexOf("(Conf"),s.lastIndexOf(")")+1); } 

Can someone explain me pls? The above code pulls it, if only the line is (Conf).

+7
java indexof
source share
2 answers

The safest way to do this is:

content.toLowerCase().indexOf(searchTerm.toLowerCase()) , so you cover 2 possible extreme cases where the content may be in lower case and the search term will be in upper case, or both will be in upper case.

+8
source share

One common solution:

 yourString.toLowerCase().indexOf("foo"); 
+3
source share

All Articles