Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indexOf Case Sensitive?

Is the indexOf(String) method case sensitive? If so, is there a case insensitive version of it?

like image 428
Brian Avatar asked Jul 14 '09 15:07

Brian


People also ask

Is indexOf case sensitive C#?

IndexOf Method is by default case sensitive.

Is contains case sensitive in JavaScript?

Both String#includes() and String#indexOf() are case sensitive. Neither function supports regular expressions. To do case insensitive search, you can use regular expressions and the String#match() function, or you can convert both the string and substring to lower case using the String#toLowerCase() function.

What is indexOf in Java?

The indexOf() method returns the position of the first occurrence of specified character(s) in a string. Tip: Use the lastIndexOf method to return the position of the last occurrence of specified character(s) in a string.


1 Answers

The indexOf() methods are all case-sensitive. You can make them (roughly, in a broken way, but working for plenty of cases) case-insensitive by converting your strings to upper/lower case beforehand:

s1 = s1.toLowerCase(Locale.US); s2 = s2.toLowerCase(Locale.US); s1.indexOf(s2); 
like image 198
Joey Avatar answered Oct 01 '22 10:10

Joey