Created
December 21, 2022 05:22
-
-
Save imandaliya/4fc17e0abb83893529dcbbf32da5954b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compare two strings on java with neglating localization | |
public static boolean containsIgnoreCase(String src, String what) { | |
final int length = what.length(); | |
if (length == 0) | |
return true; // Empty string is contained | |
final char firstLo = Character.toLowerCase(what.charAt(0)); | |
final char firstUp = Character.toUpperCase(what.charAt(0)); | |
for (int i = src.length() - length; i >= 0; i--) { | |
// Quick check before calling the more expensive regionMatches() method: | |
final char ch = src.charAt(i); | |
if (ch != firstLo && ch != firstUp) | |
continue; | |
if (src.regionMatches(true, i, what, 0, length)) | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment