natural-sort

Natural (human alpha-numeric) sort in Microsoft SQL 2005

We have a large database on which we have DB side pagination. This is quick, returning a page of 50 rows from millions of records in a small fraction of a second. Users can define their own sort, basically choosing what column to sort by. Columns are dynamic - some have numeric values, some dates and some text. While most sort as expe...

Natural Sorting algorithm

How do you sort an array of strings naturally in different programming languages? Post your implementation and what language it is in in the answer. ...

Natural Sort in MySQL

Is there an elegant way to have performant, natural sorting in a MySQL database? For example if I have this data set: Final Fantasy Final Fantasy 4 Final Fantasy 10 Final Fantasy 12 Final Fantasy 12: Chains of Promathia Final Fantasy Adventure Final Fantasy Origins Final Fantasy Tactics Any other elegant solution than to split up th...

Natural Sort Order in C#

Anyone have a good resource or provide a sample of a natural order sort in C# for an FileInfo array? I am implementing the IComparer interface in my sorts. ...

How can I sort a hash's keys naturally?

I have a Perl hash whose keys start with, or are, numbers. If I use, foreach my $key (sort keys %hash) { print $hash{$key} . "\n"; } the list might come out as, 0 0001 1000 203 23 Instead of 0 0001 23 203 1000 ...

IComparer problem + How do I sort an array of strings naturally (FILE_10 > FILE_2) in .NET?

SOLVED at the bottom of my post. Or more specifically: I have a bunch of FileInfo objects (I need the FileInfo objects to exclude hidden, system and reparse point files). I need to sort FileInfo[] naturally based on their FileInfo.FullName. So FILE_10.ext should come after FILE_2.ext. Luckily the FileInfo[] contains files of only one ...

How to sort and display mixed lists of alphas and numbers as the users expect?

Our application has a CustomerNumber field. We have hundreds of different people using the system (each has their own login and their own list of CustomerNumbers). An individual user might have at most 100,000 customers. Many have less than 100. Some people only put actual numbers into their customer number fields, while others use ...

Obtaining numeric/normalized representation of strings to aid in 'natural sort ordering' of titles in DB

I'd like to store an additional column in a table as a 'sort value', which is a numeric representation of the title column, such that the order of such values represents the string's natural alphabetical sort order. Ie, so that I can retrieve rows ordered by the sort value, and they'll be in natural sort order - and when I insert a new ...

How to implement a natural sort algorithm in c++?

I'm sorting strings that are comprised of text and numbers. I want the sort to sort the number parts as numbers, not alphanumeric. For example I want: abc1def, ..., abc9def, abc10def instead of: abc10def, abc1def, ..., abc9def Does anyone know an algorithm for this (in particular in c++) Thanks ...

Natural sort order string comparison in Java - is one built in?

I'd like some kind of string comparison function that preserves natural sort order1. Is there anything like this built into Java? I can't find anything in the String class, and the Comparator class only knows of two implementations. I can roll my own (it's not a very hard problem), but I'd rather not re-invent the wheel if I don't hav...

LINQ and a natural sort order...

Hi, What's the easiest way to get a LINQ query (from an SQL database - does that matter?) to order strings naturally? For example, I'm currently getting these results: Project 1 Project 10 Project 2 What I'd like is to see is this: Project 1 Project 2 Project 10 The query I'm using is this: return from p in dataContext.Project...

Natural sort in C - "array of strings, containing numbers and letters"

Looking for a proven to work algorithm for production. Did see this example but not finding much else on the web or in books. i.e. file_10.txt > file_2.txt Thanks. ...

C#: Implementation of, or alternative to, StrCmpLogicalW in shlwapi.dll

For natural sorting in my application I currently P/Invoke a function called StrCmpLogicalW in shlwapi.dll. I was thinking about trying to run my application under Mono, but then of course I can't have this P/Invoke stuff (as far as I know anyways). Is it possible to see the implementation of that method somewhere, or is there a good, c...

Natural order sort for Emacs Lisp

Has anyone implemented a natural order sort in Emacs Lisp? I know it's not hard to write, but it's easier to borrow someone else's work. (Yeah, I can't believe I just searched for an Emacs function and couldn't find it.) ...

IList with an implicit sort order

I'd like to create an IList<Child> that maintains its Child objects in a default/implicit sort order at all times (i.e. regardless of additions/removals to the underlying list). What I'm specifically trying to avoid is the need for all consumers of said IList<Child> to explicitly invoke IEnumerable<T>.OrderBy() every time they want to...

php natural order sorting of mysql select rows

Hi, I'm running a select that returns alphanumeric results, e.g: ABC-1 ABC-2 ABC-10 SAM-1 SAM-2 SAM-10 SAM-20 I've tried using: ORDER BY CAST(mid(field_name, 6, LENGTH(class) -5) AS unsigned) and ORDER BY filed_name + 0 ASC this has helped put some order but I cant seem to order -2 before -10 many thanks ...

natural sort of text and numbers, JavaScript

I'm looking for the easiest way to sort an array that consists of numbers and text, and a combination of these. E.g. '123asd' '19asd' '12345asd' 'asd123' 'asd12' turns into '19asd' '123asd' '12345asd' 'asd12' 'asd123' This is going to be used in combination with the solution to another question I've asked here. The sorting functi...

Natural sort for SQL Server?

I have a column that is typically only numbers (sometimes it's letters, but that's not important). How can I make it natural sort? Currently sorts like this: {1,10,11,12,2,3,4,5,6,7,8,9} I want it to sort like this: {1,2,3,4,5,6,7,8,9,10,11,12} ...

Numeric order when returning results from MySQL

I have the following types of titles in a table in my db: Topic 1 blah blah Topic 2 blah blah Topic 3 blah blah ... Topic 10 blah blah Topic 11 blah blah etc... The select query will always return the results like this: Topic 1 blah Topic 10 blah blah Topic 11 blah ...leaving out Topic 2, Topic 3 etc... until after all the teens...

Natural Sort in NHibernate

I've got a hibernate query that returns a list of objects and I want to order by a title. This is a user maintained field and some of our customers like prefixing their titles with numbers, this isn't something I can control. The data is something like this: - 1 first thing - 2 second thing - 5 fifth thing - 10 tenth thing - 20 twe...