От: | yg | ||
Дата: | 10.12.07 13:50 | ||
Оценка: | 439 (21) | ||
#Имя: | FAQ.dotnet.string.compare |
string s1, s2;
int res;
s1 = "CSK."; s2 = "CSK-";
res = CompareTo(s1, s2);
Console.WriteLine(res);
s1 = "CSK.S"; s2 = "CSK-V";
res = CompareTo(s1, s2);
Console.WriteLine(res);
1
-1
The .NET Framework uses three distinct ways of sorting: word sort, string sort, and ordinal sort. Word sort performs a culture-sensitive comparison of strings. Certain nonalphanumeric characters might have special weights assigned to them; for example, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. String sort is similar to word sort, except that there are no special cases; therefore, all nonalphanumeric symbols come before all alphanumeric characters. Ordinal sort compares strings based on the Unicode values of each element of the string.