B
benny
Anybody can explain why
String.Compare("4","¢w3")=1;
but
String.Compare("3","¢w3")=-1;
the '¢w ' is 0x2015
String.Compare("4","¢w3")=1;
but
String.Compare("3","¢w3")=-1;
the '¢w ' is 0x2015
benny said:Anybody can explain why
String.Compare("4","¢w3")=1;
but
String.Compare("3","¢w3")=-1;
the '¢w ' is 0x2015
As it happens, Char.GetUnicodeCategory( '\u2015') returns
UnicodeCategory.DashPunctuation.
So I tried:
String.Compare( "4", "-3");
String.Compare( "3", "-3");
And I came up with 1 and -1 again.
Jon said:I suspect this is the same reason as another recent string comparison
question. Basically the dash is being treated as a word joining
character which is compared differently so that if you're looking at a
word list, "co-ordinate" and "coordinate" come together. The test above
is effectively making a list look like:
3
-3
4
which looks funny until you think of:
coordinate
co-ordinate
cop
when it looks absolutely fine.