I am looking for a natural sort technique like Windows explorer does.
For example, if I have the Alpha-numeric Array -
var array = new[]{"B01 002", "B01 0010", "01", "B01 001", "B10 001", "B01 01", "1", "B1 001", "B02 001", "A1"};
I am expecting this to be sorted in the below Order-
[01, 1, A1, B01 001, B01 01, B01 002, B01 0010, B1 001, B02 001, B10 001]
This is precisely the way that Windows Explorer does it-
I have tried the solutions in the below thread-
- Natural Sort Order in C# - The accepted solution does the trick, but I am not allowed to use "shlwapi.dll" in my case. The rest of the answers do not sort right for the strings starting with char 'B' in the above example.
- Natural sort order in C# - implementation - Sort order is not as expected.
- Natural Sorting in C# & naturalstringcomparer.cs - I tried the approaches in these articles as well, but even these don't sort right.
No other constraint on the approach taken. Either it is LINQ, Regex, Extention, or Interface approach that can be used to replicate the sort order done by "shlwapi.dll"