T
Tony Johansson
Hi!
Below is a simple program that is using the Comparer class to compare two
strings named str1 and str2.
If I use the 0x040A as the first argument to the CultureInfo I use the
traditional sort order accoding to the MSDN documentation that you can find
at the bottom.
The WriteLine statement in the program is writing 1 as the value meaning
that str1 > str2.
Can somebody explain how this works because the comparing is not based on
the ascii table ?
I mean if we use the normal ascii table we would have said that str1 < str2
because the letter l is less then u.
public static void Main()
{
// Creates the strings to compare.
String str1 = "llegar";
String str2 = "lugar";
Comparer myCompTrad = new Comparer(new CultureInfo(0x040A, false));
Console.WriteLine(" Traditional Sort : {0}",
myCompTrad.Compare(str1, str2));
}
The Spanish (Spain) culture uses two culture identifiers, 0x0C0A using the
default international sort order, and 0x040A using the traditional sort
order. If the CultureInfo is constructed using the es-ES culture name, the
new CultureInfo uses the default international sort order. For the
traditional sort order, the object is constructed using the name
es-ES_tradnl.
//Tony
Below is a simple program that is using the Comparer class to compare two
strings named str1 and str2.
If I use the 0x040A as the first argument to the CultureInfo I use the
traditional sort order accoding to the MSDN documentation that you can find
at the bottom.
The WriteLine statement in the program is writing 1 as the value meaning
that str1 > str2.
Can somebody explain how this works because the comparing is not based on
the ascii table ?
I mean if we use the normal ascii table we would have said that str1 < str2
because the letter l is less then u.
public static void Main()
{
// Creates the strings to compare.
String str1 = "llegar";
String str2 = "lugar";
Comparer myCompTrad = new Comparer(new CultureInfo(0x040A, false));
Console.WriteLine(" Traditional Sort : {0}",
myCompTrad.Compare(str1, str2));
}
The Spanish (Spain) culture uses two culture identifiers, 0x0C0A using the
default international sort order, and 0x040A using the traditional sort
order. If the CultureInfo is constructed using the es-ES culture name, the
new CultureInfo uses the default international sort order. For the
traditional sort order, the object is constructed using the name
es-ES_tradnl.
//Tony