Is there a way in .NET/C# to sort a List
according to a custom alphabetical order?
I have a list of words:
{ \"badum\", \"
You can pass custom sorter to the List.Sort() method:
List<string> foo = new List<string>();
foo.Sort((a, b) => a.CompareTo(b));
This will sort the list in place depending on which criteria you want to use (above obviously does just a regular string comparison).
I would definitely start with creating a RuleBasedCollator. Figuring out the rules that you want is one of the harder tasks.
There is a project that provides .net bindings over icu which may suit you.
If that doesn't meet your requirements, and you decide to write your own, the Unicode Collation Algorithm is a good resource. Keep in mind that natural language sorting conceptually (although many optimizations are possible) involves separate passes with increasing specificity. The first pass will look for so-called primary distinctions (usually ignoring differences of case and certain diacritics and punctuation) if there are no differences and the number of primary units in both strings is the same, then you can make the second pass, this time taking into account diacritic differences, if any. Next you process the case distinctions and finally punctuation distinctions.