natural-sort

Natural sort for SQL Server?

自作多情 提交于 2019-12-04 03:47:05
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} DiGi IsNumeric is "broken", ISNUMERIC(CHAR(13)) returns 1 and CAST will fail. Use ISNUMERIC(textval + 'e0'). Final code: ORDER BY PropertyName, CASE ISNUMERIC(MixedField + 'e0') WHEN 1 THEN 0 ELSE 1 END, -- letters after numbers CASE ISNUMERIC(MixedField + 'e0') WHEN 1 THEN CAST(MixedField AS INT) ELSE 0 END, MixedField You can mix order parameters...

Is there a Case-Sensitive Natural-Sorting-Function in Delphi?

允我心安 提交于 2019-12-04 03:20:39
问题 I want to order a List of Strings with different Options. Options are: Alphabetical Sort or Logical Sort Case-Sensitive or not Case-Sensitive Ascending or Descending I have all branches covered except for: Case-Sensitive, Logical-Sort. (Pretty much NatSort from php) Now I am trying to find a Function that does what I need. In order to get a not-case-sensitive logical order I implemented a call to the StrCmpLogicalW-Function in the shlwapi.dll https://docs.microsoft.com/en-us/windows/desktop

How can I sort a hash's keys naturally?

旧时模样 提交于 2019-12-03 17:11:21
问题 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 回答1: foreach my $key (sort { $a <=> $b} keys %hash) { print $hash{$key} . "\n"; } The sort operation takes an optional comparison "subroutine" (either as a block of code, as I've done here, or the name of a subroutine). I've supplied an in-line comparison that treats the keys as numbers

Combine alphabetical and natural order (aka. User sane sorting)

故事扮演 提交于 2019-12-03 07:47:07
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

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

拜拜、爱过 提交于 2019-12-02 08:53:44
问题 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. 回答1: I assume you already know the C standard library qsort() function: void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *); That last parameter is a function pointer , which means you can pass any function to it. You could use strcmp() , in fact, but that would give you ASCIIbetical, and you

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

≡放荡痞女 提交于 2019-12-02 03:08:19
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. I assume you already know the C standard library qsort() function: void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *); That last parameter is a function pointer , which means you can pass any function to it. You could use strcmp() , in fact, but that would give you ASCIIbetical, and you specifically want a natural sort. In that case, you could write one pretty easily: #include <ctype.h> int

How to sort an alphanumeric array in ruby

时间秒杀一切 提交于 2019-12-01 21:33:13
How I can sort array data alphanumerically in ruby? Suppose my array is a = [test_0_1, test_0_2, test_0_3, test_0_4, test_0_5, test_0_6, test_0_7, test_0_8, test_0_9, test_1_0, test_1_1, test_1_2, test_1_3, test_1_4, test_1_5, test_1_6, test_1_7, test_1_8, test_1_9, test_1_10, test_1_11, test_1_12, test_1_13, test_1_14, ...........test_1_121...............] I want my output to be: . . . test_1_121 . . . test_1_14 test_1_13 test_1_12 test_1_11 test_1_10 test_1_9 test_1_8 test_1_7 test_1_6 test_1_5 test_1_4 test_1_3 test_1_2 test_1_1 test_0_10 test_0_9 test_0_8 test_0_7 test_0_6 test_0_5 test_0

Is there a Case-Sensitive Natural-Sorting-Function in Delphi?

一曲冷凌霜 提交于 2019-12-01 17:17:16
I want to order a List of Strings with different Options. Options are: Alphabetical Sort or Logical Sort Case-Sensitive or not Case-Sensitive Ascending or Descending I have all branches covered except for: Case-Sensitive, Logical-Sort. (Pretty much NatSort from php) Now I am trying to find a Function that does what I need. In order to get a not-case-sensitive logical order I implemented a call to the StrCmpLogicalW-Function in the shlwapi.dll https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-strcmplogicalw However, I can not find a Case-Sensitive equivalent to

Django Query Natural Sort

给你一囗甜甜゛ 提交于 2019-12-01 14:13:01
Let's say I have this Django model: class Question(models.Model): question_code = models.CharField(max_length=10) and I have 15k questions in the database. I want to sort it by question_code , which is alphanumeric. This is quite a classical problem and has been talked about in: http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/ Does Python have a built in function for string natural sort? I tried the code in the 2nd link (which is copied below, changed a bit), and notice it takes up to 3 seconds to sort the data. To make sure about the function's performance, I write a test

Using MySQL sort varchar column numerically with cast as unsigned when the column can begin or end with letters

橙三吉。 提交于 2019-12-01 10:34:24
I've ran into something I'm not really sure how to handle here. I'm building a database to store information on sports cards, and I'm having a bit of an issue with some sorting when I want to see certain cards. For background, each card (row in the database) has information on year, set the card is from, player on the card, and card number (there's more info than that, but this is all that's relevant here). When I see results, I want things to be sorted by year, then set, then player, then card number. Everything but card number is working fine, as year is just an integer, and set and player