I am trying to sort a list of Greek Unicode strings, but I can't get the .NET framework to correctly sort or compare the accented vowels. For example
String.Compare(" "," ") // or String.Compare("\u1f00","\u1f30");
always returns 0 and
String.Compare(" ","α")
always returns -1 regardless of the Culture information (current, invariant, Greek) I use in the other arguments of the Compare function. Is there a way to make the first comparison return a negative number

String.Compare with Unicode characters
zu35926
yanyee
Or you can also use the suggestion i made if you are running on Vista. :-)
If you are running .NET 2.0 you can also use normalization support to strip the diacritics....
Hasan ACAR
Did someone say my name :-)
The answer to this question can be found in the following blog post:
The city elders won't give this string weight, either (aka On being consistently dead wrong, aka Ordinal or bust )
Michael [MSFT]
NLS Collation/Locale/Keyboard Technical Lead
Globalization Infratstructure and Font Technologies
lightiv
String.Compare(" ", " ", StringComparison.Ordinal);Console.WriteLine(compareInfo.Compare(" ", " ", CompareOptions.Ordinal));
datahook
I did check the Latin Extended Additional characters, and they work. It just seems to be a problem with the Greek Extended characters.
KingKarter
Sharath paleri
Actually
String.Compare(" ","α")
returns -1 when it should as you said return 0. And that is another error different from the one I mentioned, as α is in the normal Greek code page whereas is in the Greek Extended page. So it seems to me that
String.Compare(Greek Extended character, Greek Extended character)=0
String.Compare(Greek normal character, Greek Extended character)=1
always regardless of what the actual Greek letters are. At least
String.Compare(Greek normal character, Greek normal character)
is correct, giving -1, 0 or 1 depending upon the two letters.
CompareStringOrdinal doesn't help, as Ordinal comparisons work in .NET and anyway do not order the Extended Greek letters correctly. As someone else pointed out, the problem seems to be in the Windows API.
Dottj
I don't know Greek but isn't it possible that the mentioned string compare functions are correct when they return 0 meaning that the mentioned compared characters are linguistic equal
String.Compare(" ","α")
CompareStringOrdinal in Vista can be used to check for binary equality I am not running Vista so I can't try this out.
georgeob
I am (and all my users will be) using .NET 2.0, but normalization does not remove the accents, because the accents are not separate Unicode characters, but there is one Unicode character that represents the character and the accents together. So
" ".Normalize()
equals
" " // = "\u1f96"
for all the Normalize forms.
GShap
winstonSmith
CultureInfo greek = CultureInfo.GetCultureInfo("el-GR");
for (char ch1 = '\u1f00'; ch1 < '\u1ffe'; ++ch1)
for (char ch2 = ++ch1; ch2 < '\u1fff'; ++ch2) {
if (0 != String.Compare(ch1 + "", ch2 + "", false, greek))
Console.WriteLine("found one");
}
JackG
voltagefreak
Jason D. Camp