We develop high-performance Web sites and Facebook applications. Our core values are rooted in simple design, clean code and standards-compliant html.


-->

The Alphanum Algorithm

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.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Post a Comment

Your email is never shared. Required fields are marked *

*
*