Skip to main content

Natural String Order

Posted by skelvin on January 13, 2006 at 6:53 AM PST

Treats contained numbers sensible when comparing strings

Natural Order
(e.g. implemented in Windows XP's file explorer)

rfc 1.txt
rfc 822.txt
rfc 2086.txt
           

Java's default Order
Somewhat stupid...

rfc 1.txt
rfc 2086.txt
rfc 822.txt
           

(Kudos to Martin Pool for the example.)

When I needed a natural sort feature in my Java app I started to google and to look in a few other places
(like Apache Commons).
There should be plenty of code out there that does this, right? Nope.
I found a page with a description of the problem and links to implementations in a couple of programming languages:
Natural Order String Comparison

There's a single Java implementation, but that one cannot handle texts that contain non-ascii characters.
So it would fail in my German application, where texts contain funny characters such as these:

Im

Related Topics >>