Java: equivalent to C's strnicmp? (both startsWith and ignoreCase)

Posted by Jason S on Stack Overflow See other posts from Stack Overflow or by Jason S
Published on 2010-04-08T19:47:37Z Indexed on 2010/04/08 20:13 UTC
Read the original article Hit count: 113

Filed under:
|

String string1 = "abCdefGhijklMnopQrstuvwYz"; String string2 = "ABC";

I had been using string1.startsWith(string2), which would return false in the above example, but now I need to ignore case sensitivity, and there is not a String.startsWithIgnoreCase().

Besides doing

 string1.toLowerCase.startsWith(string2.toLowerCase());

is there an efficient way to see if string1 starts with string2 in a case-insensitive way?

© Stack Overflow or respective owner

Related posts about java

Related posts about string