“The 1,11,2 Problem”, natural sorting of numbers and characters.

I’m sure everyone has run into this problem! You’re looking at a list in your file browser, or a maybe a list of tracks, the filenames or track numbers contain both numbers and characters, and the ordering is against logic: “1,11,2″ instead of “1,2,11″. Often times we will rename filenames to be have a preceding zero to fix the problem, “01, 02, 11″, however that isn’t compulsory! This error happens because the numbers are seen to the software as as “string” of characters and their numeric value is not considered when it is sorted. Here is a great resource with examples in many programming languages on how to sort the “strings” considering both the alpha and numeric values in the “strings”: The Alphanum Algorithm

This entry was posted in Code. Bookmark the permalink.

Comments are closed.