R
Rene
Hi,
It was my understanding that when comparing strings using
"OrdinalIgnoreCase" as the method to compare the strings, the .Net compared
the strings by first capitalizing all of the characters on the string and
then making an ordinal comparison (Unicode code point comparison).
I guess I was wrong (or I am not getting something) because my experiments
prove otherwise.
In the code below, compare1 returns zero proving that if I manually
capitalize the strings and then compare them the .Net says they are the
same.
However, compare2 does not return zero, so this means that the .Net is doing
something different that what I assumed.
Could someone please tell me why compare1 and compare2 are returning
different values?
Thank you.
---------------------------------------------------------
// LATIN CAPITAL LETTER I (U+0049)
string capitalLetterI = "I";
// LATIN SMALL LETTER DOTLESS I (U+0131)
string smallLetterDotlessI = "\u0131";
string upper1 = smallLetterDotlessI.ToUpper();
string upper2 = capitalLetterI.ToUpper();
int compare1 = string.Compare(upper1, upper2, StringComparison.Ordinal);
int compare2 = string.Compare(smallLetterDotlessI, capitalLetterI,
StringComparison.OrdinalIgnoreCase);
It was my understanding that when comparing strings using
"OrdinalIgnoreCase" as the method to compare the strings, the .Net compared
the strings by first capitalizing all of the characters on the string and
then making an ordinal comparison (Unicode code point comparison).
I guess I was wrong (or I am not getting something) because my experiments
prove otherwise.
In the code below, compare1 returns zero proving that if I manually
capitalize the strings and then compare them the .Net says they are the
same.
However, compare2 does not return zero, so this means that the .Net is doing
something different that what I assumed.
Could someone please tell me why compare1 and compare2 are returning
different values?
Thank you.
---------------------------------------------------------
// LATIN CAPITAL LETTER I (U+0049)
string capitalLetterI = "I";
// LATIN SMALL LETTER DOTLESS I (U+0131)
string smallLetterDotlessI = "\u0131";
string upper1 = smallLetterDotlessI.ToUpper();
string upper2 = capitalLetterI.ToUpper();
int compare1 = string.Compare(upper1, upper2, StringComparison.Ordinal);
int compare2 = string.Compare(smallLetterDotlessI, capitalLetterI,
StringComparison.OrdinalIgnoreCase);