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?
The regionMatches
method has a case sensitive parameter.
Use StringUtils library.
StringUtils.startsWithIgnoreCase("abCdefGhijklMnopQrstuvwYz", "ABC"); // true
http://commons.apache.org/lang/api/org/apache/commons/lang/StringUtils.html#startsWithIgnoreCase%28java.lang.String,%20java.lang.String%29
How about this:
string2.equalsIgnoreCase(string1.substring(0, string2.length())
string.toLowerCase().startsWith(string2.toLowerCase())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With