Javascript : natural sort of alphanumerical strings

This is now possible in modern browsers using localeCompare. By passing the numeric: true option, it will smartly recognize numbers. You can do case-insensitive using sensitivity: ‘base’. Tested in Chrome, Firefox, and IE11. Here’s an example. It returns 1, meaning 10 goes after 2: ’10’.localeCompare(‘2’, undefined, {numeric: true, sensitivity: ‘base’}) For performance when sorting large … Read more

Natural Sort Order in C#

The easiest thing to do is just P/Invoke the built-in function in Windows, and use it as the comparison function in your IComparer: [DllImport(“shlwapi.dll”, CharSet = CharSet.Unicode)] private static extern int StrCmpLogicalW(string psz1, string psz2); Michael Kaplan has some examples of how this function works here, and the changes that were made for Vista to … Read more