natural-sort

array_multisort with natural sort

自闭症网瘾萝莉.ら 提交于 2019-12-17 19:02:41
问题 Is it possible to sort multiple dimensional array by multiple columns using natural sort in PHP? Here is an example. Suppose I have a 2D array of data, e.g., $array[1]['Name'] = 'John'; $array[1]['Age'] = '20'; $array[1]['Code'] = 'ABC 12'; $array[2]['Name'] = 'John'; $array[2]['Age'] = '21'; $array[2]['Code'] = 'ABC 1'; $array[3]['Name'] = 'Mary'; $array[3]['Age'] = '20'; $array[3]['Code'] = 'ABC 10'; I want to sort this array by name (ASC), then by age (DESC), and by code (ASC), all will be

LINQ and a natural sort order [duplicate]

青春壹個敷衍的年華 提交于 2019-12-17 18:38:43
问题 This question already has answers here : Natural Sort Order in C# (17 answers) Closed 2 years ago . 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.Projects orderby p.Name select p; 回答1: There is no built-in way to do this using

PostgreSQL ORDER BY issue - natural sort

孤街醉人 提交于 2019-12-17 16:34:16
问题 I've got a Postgres ORDER BY issue with the following table: em_code name EM001 AAA EM999 BBB EM1000 CCC To insert a new record to the table, I select the last record with SELECT * FROM employees ORDER BY em_code DESC Strip alphabets from em_code usiging reg exp and store in ec_alpha Cast the remating part to integer ec_num Increment by one ec_num++ Pad with sufficient zeors and prefix ec_alpha again When em_code reaches EM1000, the above algorithm fails. First step will return EM999 instead

Javascript : natural sort of alphanumerical strings

妖精的绣舞 提交于 2019-12-16 19:21:57
问题 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 function in itself works, what I need is a function that can say that that '19asd' is smaller than '123asd'. I'm writing this in JavaScript. Edit: as adormitu pointed out,

Sorting nvarchar column containing alphanumeric values

白昼怎懂夜的黑 提交于 2019-12-13 08:31:48
问题 One of my columns in a SQL Server 2005 table contains alphanumeric values and I want to sort the rows as per the alphanumeric sorting. HOUSE_NO is a NVARCHAR column and it contains values like this: - 2/1 NAWOG - 1/1 - 2/1 A - 1/2 A GOLCHA - 1 - 2 - SHASWAT KUTIR - 3 A - 11/1 - 11 And I want them to be sorted as: - 1 - 1/1 - 1/2 A GOLCHA - 2 - 2/1 A - 2/1 NAWAG - 3 A - 11 - 11/1 - SHASWAT KUTIR I have tried many methods but not successful. I need your suggestions 回答1: Yuck. This is not

In Ruby on Rails, after “gem install <gem_name>”, how to make it extend Array, or use its class method?

江枫思渺然 提交于 2019-12-13 04:13:08
问题 Summary: after I gem install <gem_name> , how do I make it extend Array which the gem can do? Details: I see a gem for "natural language sort", which is http://rubygems.org/gems/naturalsort http://naturalsort.rubyforge.org/ so I am using Ruby 1.9.2 and Rails 3.0.6, and I add the line gem 'naturalsort' into Gemfile , and do a bundle install and restart the server, but now, for some reason, I still can't do a NaturalSort::naturalsort ['a', 'b', 'c', 'd', 'A', 'B', 'C', 'D'] in my helper file?

Naturally sort a list of alpha-numeric tuples by the tuple's first element in Python

a 夏天 提交于 2019-12-12 12:23:40
问题 A previous stackoverflow question explains how to sort a list of strings alpha-numerically. I would like to sort a list of tuples alphanumerically by the tuple's first element. Example 1: >>> sort_naturally_tuple([('b', 0), ('0', 1), ('a', 2)]) [('0', 1), ('a', 2), ('b', 0)] Example 2: >>> sort_naturally_tuple([('b10', 0), ('0', 1), ('b9', 2)]) [('0', 1), ('b9', 2), ('b10', 0)] Update: To emphasize the alphanumeric factor, please review example 2. 回答1: Using the second answer from the other

Sort filenames naturally with Qt

柔情痞子 提交于 2019-12-12 07:24:41
问题 I am reading a directories content using QDir::entryList() . The filenames within are structured like this: index_randomNumber.png I need them sorted by index , the way the Windows Explorer would sort the files so that I get 0_0815.png 1_4711.png 2_2063.png ... instead of what the sorting by QDir::Name gives me: 0_0815.png 10000_6661.png 10001_7401.png ... Is there a built-in way in Qt to achieve this and if not, what's the right place to implement it? 回答1: If you want to use QCollator to

Sort a collection alphanumerically in backbone

Deadly 提交于 2019-12-12 05:29:40
问题 I have written a comparator to sort the collection based on "id" like this: comparator: function(coll) { return coll.get('id'); } This works fine for input: "id-1, id-0, id-2, id-199" to sort as "id-0, id-1, id-2, id-199" But does not sort numerically here: "id-1, id-0, id-2, id-199, id-99" as "id-0, id-1, id-2, id-199, id-99" -- id-99 should be before id-199. 回答1: As commented by @suish the way this was solved was by performing a replace of all non-numerical part with empty string. coll.get(

Natural sort for SQL Server

一个人想着一个人 提交于 2019-12-12 03:07:11
问题 Similar Questions Similar questions have been asked before, but always have specific qualities to the data which allow a more targeted "split it up and just sort by this part" approach, which does not work when you don't know the structure of the data in the column - or even the column, frankly. In other words, not a generic, "Natural" sort order - something roughly equivalent to SELECT * FROM [parts] ORDER BY [part_category] DESC, [part_number] NATURAL DESC My Situation I have a DataView in