I was reading java.lang.String equals ignore case implementation and trying figure out why is there a lower case compare after upper case is already compared? Are there languages where this matters ,where upper cases may not match but lower cases may match?
// Code from java.lang.String class
public boolean regionMatches(boolean paramBoolean, int paramInt1, String paramString, int paramInt2, int paramInt3) {
char[] arrayOfChar1 = this.value;
int i = paramInt1;
char[] arrayOfChar2 = paramString.value;
int j = paramInt2;
if (paramInt2 < 0 || paramInt1 < 0 || paramInt1 > this.value.length - paramInt3 || paramInt2 > paramString.value.length - paramInt3)
return false;
while (paramInt3-- > 0) {
char c1 = arrayOfChar1[i++];
char c2 = arrayOfChar2[j++];
if (c1 == c2)
continue;
if (paramBoolean) {
char c3 = Character.toUpperCase(c1);
char c4 = Character.toUpperCase(c2);
// Why is java comparing to Lower case here
if (c3 == c4 || Character.toLowerCase(c3) == Character.toLowerCase(c4))
continue;
}
return false;
}
return true;
}
That’s all about Java String contains ignore case. How to Print to File in Python? Remove nan From List In Python?
Case-insensitivity is defined as by String.equalsIgnoreCase (String). A null CharSequence will return false. This one will be better than regex as regex is always expensive in terms of performance. you can implement your own custom containsIgnoreCase using java.lang.String.regionMatches ignoreCase : if true, ignores case when comparing characters.
you can implement your own custom containsIgnoreCase using java.lang.String.regionMatches ignoreCase : if true, ignores case when comparing characters.
Definition and Usage The equalsIgnoreCase () method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase () method to compare two strings lexicographically, ignoring case differences.
Some characters exist only in lower case, some only exist in upper case. For example, in Germany we have the character "ß" which is lower case. There is no upper case version of it.
I assume that the same can happen in the opposite direction in other languages.
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