Have you ever tried to sort a set of strings programmatically only to be confused by the output? This usually happens with strings that contain a mixed set of numbers and letters.
David Koelle wrote a solution for this problem in 1997 called the Alphanum Algoritm.
The algorithm breaks strings into chunks, where a chunk contains either all alphabetic characters, or all numeric characters. These chunks are then compared against each other. If both chunks contain numbers, a numerical comparison is used. If either chunk contains characters, the ASCII comparison is used.
Absolutely brilliant approach to a common problem. His approach is remarkably elegant and well thought out, and considers users’ needs above developers’ convenience. We in the software industry too often forget the one most important aspect of writing software: it’s meant to be used, either by us or someone else.
I look forward to using this code on a couple projects I’m working on now.













