1

I have 2 characters that I'm trying to compare using Globalization.SortKey and just out of the box it is sorting almost exactly how I would like it to with 'a' being first and 'z' being last (then followed by special characters. The one problem is it has "Aa" after "a", is there anyway to switch the order so that the capital letters are put at the top of each letter instead of the bottom?

public static bool ShouldSecondComeFirst( string first, string second ){
    CompareInfo = new CultureInfo( "en-US", false ).CompareInfo;
    SortKey sortF = compInfo.GetSortKey( f );
    SortKey sortS = compInfo.GetSortKey( s );
    if( SortKey.Compare( sortF, sortS) == 1 )
        return true;
    return false;
}

The list output looks something like this

a.txt
Aa.txt
b.txt
Z.txt

but I need it to be

Aa.txt
a.txt
b.txt
Z.txt
WWZee
  • 494
  • 2
  • 8
  • 23
  • why don't you have a look here: http://stackoverflow.com/questions/12077182/c-sharp-sort-files-by-natural-number-ordering-in-the-name – Daniel A. White Dec 14 '16 at 19:26
  • @DanielA.White those answers seem really useful for the numeric portion of a sorted list but my problem is more in the alphabetical side – WWZee Dec 14 '16 at 20:03
  • 1
    You can write your own comparer by implementing the IComparer interface, see this for more information and examples https://msdn.microsoft.com/en-us/library/system.collections.icomparer.compare%28v=vs.110%29.aspx – erotavlas Dec 14 '16 at 21:14

0 Answers0