Solitaire
Well-known member
The Array.Sort method sorts alphabetically when mixing upper and lowercase letters: lower first then upper for each letter separately.
When using a second optional parameter, it will sort using ASCII values, with all uppercase letters first.
Array.Sort(stringarray, StringComparer.Ordinal)
However, unable to sort alphabetically with upper first then lower for each letter separately. This is how it should be sorted and the way it's done in Excel.
When using a second optional parameter, it will sort using ASCII values, with all uppercase letters first.
Array.Sort(stringarray, StringComparer.Ordinal)
However, unable to sort alphabetically with upper first then lower for each letter separately. This is how it should be sorted and the way it's done in Excel.
VB.NET:
Sub Main()
Dim stary() As String = {"a", "b", "D", "A", "d", "c", "C", "B"}
Array.Sort(stary) 'sorts alphabetically, lowercase first for each letter
For x As Integer = 0 To 7
Console.WriteLine(stary(x))
Next
Console.WriteLine()
Array.Sort(stary, StringComparer.Ordinal) 'sorts using ASCII values, all uppercase letters first
For x As Integer = 0 To 7
Console.WriteLine(stary(x))
Next
Console.WriteLine()
Array.Sort(stary, StringComparer.OrdinalIgnoreCase) 'same results as Array.Sort(stary)
For x As Integer = 0 To 7
Console.WriteLine(stary(x))
Next
Console.ReadLine()
End Sub