I thought this would be easy to find premade, but it seems any solution I can find on the web solves only part of the problem.
I want to sort a list of Filenames (and the files have mostly been named after persons and/or addresses) that have been given by users, sometimes in different languages (mostly german, with a bit of french and italian mixed in here and there, and rarely any other western language).
The idea is to present this list ordered in a way that the (german) users generally deem sane. That means the order should follow the java.text.Collator for Locale.GERMAN, but at the same time the expectation is to make an exception for numbers in the string, so “10” comes after “2”.
I have found code to do the natural sorting on the web, but it relies on comparing character by character (and Collator doesn’t support that). I could hack something with substring, but inside a comparator it doesn’t deem me the brightest idea to create multiple substrings on each compare-call.
Any ideas how to implement this efficiently (in both execution time and implementation time), or better yet a tested and ready-to-use implementation?
If you use the Comparator suggested by @millimoose (http://www.davekoelle.com/alphanum.html) modify it to pass the Collator
this code seems to have a problem, for example “01” is grater then “2”. But this depends on you preference, if this is important modify it to skip the leading zeros before number compare.