How to make indexof case insensitive in Java
•
Java
I have a simple question How to use @ L_ 419_ Make indexof case insensitive in 0 @ This question has been answered in some forums, but I don't understand the answer
for instance. I have a string s = phone (CONF). I want to pull such (CONF) records, but the user is entering conf or conf or conf, etc Therefore, if the word conf is found in any case, my program should be able to extract the record
if(s.indexOf("(")>-1&& s.indexOf("Conf")>-4 && s.lastIndexOf(")")>-1) { String s1=s.substring(s.indexOf("(Conf"),s.lastIndexOf(")")+1); }
Can anyone explain? If the string is only (CONF), the above code pulls it out
Solution
The safest way is:
content. toLowerCase(). Indexof (searchterm. Tolowercase()), so you can cover two possible edge cases. When the content may be lowercase, the search term is uppercase or both
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码