natural-sort

Sort Dictionary Keys in natural order [duplicate]

牧云@^-^@ 提交于 2019-12-30 10:42:41
问题 This question already has answers here : How can I sort a dictionary by key? (25 answers) Closed 5 years ago . I want to sort dictionary keys in a "natural order". If I have a dictionary with the keys d = {"key1" : object, "key11" : object, "key2" : object, "key22" : object", "jay1" : object, "jay2" : object} I want to sort this dictionary so the result is: d = { "jay1" : object, "jay2" : object, "key_1" : object, "key_2" : object, "key_11" : object, "key_22" : object"} 回答1: You can change

How to make work DataTables with Natural sort plugin?

痴心易碎 提交于 2019-12-25 07:33:19
问题 I've seen some similar questions, but no correct answer in my case. I use the DataTables plugin to sort some tables. But we can't sort datas like numerics while they are not (nut ;-p). For example, we can't sort formatted prices like those : 2 150 000 € 4 500 000 € 225 000 € So I tried to include a DataTables plugin called "Natural sort". But it doesn't seems to work, I may do some mistakes, but I can't find them. Any help will be appreciated. All you need to see/test it : JSfiddle (try to

Sort table, using loop in MySQL with SELECT and UPDATE with NATURAL ORDER

倾然丶 夕夏残阳落幕 提交于 2019-12-25 02:47:12
问题 Some long time ago I asked HERE to help with sorting the table. And user "piotrm" gave an exellent sollution, thanks to him! It works perfect! SELECT @p:=0, @parent:=0; UPDATE page p1 JOIN ( SELECT title, CASE WHEN @parent<>parent_id THEN @p:=0 ELSE @p:=@p+1 END as position, @parent:=parent_id as parent_id FROM page ORDER BY parent_id, title DESC ) p2 ON p1.title = p2.title AND p1.parent_id = p2.parent_id SET p1.position = p2.position Now I need this code to be upgraded with NATURAL SORTING.

Alphanumeric Sorting in PostgreSQL

空扰寡人 提交于 2019-12-23 16:54:58
问题 I have this table with a character varying column in Postgres 9.6: id | column ------------ 1 |IR ABC-1 2 |IR ABC-2 3 |IR ABC-10 I see some solutions typecasting the column as bytea . select * from table order by column::bytea. But it always results to: id | column ------------ 1 |IR ABC-1 2 |IR ABC-10 3 |IR ABC-2 I don't know why '10' always comes before '2'. How do I sort this table, assuming the basis for ordering is the last whole number of the string, regardless of what the character

How to sort an alphanumeric array in ruby

左心房为你撑大大i 提交于 2019-12-20 02:26:17
问题 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

mysql natural sorting

时光总嘲笑我的痴心妄想 提交于 2019-12-19 10:40:48
问题 I have table like server(id,name,ip) . When I'm trying to sort results by name, I get: srv1,srv10,srv11,srv2,srv6 but I need the results like srv1,srv2,srv6,srv10,srv11 One idea I know is ORDER BY LENGTH(name), name but I have different lengths in name column What do I need to do? 回答1: You could try this: SELECT id,name,ip,CONVERT(SUBSTRING(name FROM 4),UNSIGNED INTEGER) num ORDER BY num; 回答2: Natural sorting is not implemented in MySQL. You should try a different approach. In this example I

Is there a way to sort so that “Vitamin B12” is not in front of “Vitamin B6”?

怎甘沉沦 提交于 2019-12-19 10:06:39
问题 In Ruby on Rails, the default sort order will be Vitamin A Vitamin B12 Vitamin B6 Is there a mechanism or quick way so that it will sort by a natural language way so that B6 shows before B12 ? 回答1: Try something like: class Array def smart_sort sort_by{|s| (' '+s).scan(/(\d+)|(\D+)/).map{|d, s| s || d.to_i}} end end a = ['Vitamin A', 'Vitamin B12', 'Vitamin B6'] p a.smart_sort # => ["Vitamin A", "Vitamin B6", "Vitamin B12"] It sorts alternatively by digits and by non-digits. b = ['3c17d',

Java String Number Comparator

懵懂的女人 提交于 2019-12-18 04:14:22
问题 I have a method returning a list of String that need to be sorted. However, I'm running into the old String number sorting issue and was wondering if any one could assist with a Comparator implementation or point me in the direction of one. The list is going to return something list this: State Lower Legislative District 1 State Lower Legislative District 11 State Lower Legislative District 12 ... State Lower Legislative District 2 ... State Lower Legislative District 100 ... State Upper

IComparer for natural sorting [duplicate]

早过忘川 提交于 2019-12-18 04:09:40
问题 This question already has answers here : Natural Sort Order in C# (17 answers) Closed 2 years ago . I have been hunting around for a solution to this for a while now. When I sort the below using a string sort I have a list of: 10 10b 1111 1164 1174 23 23A 23B 23D 23E I really want the list to be: 10 10b 23 23A 23B 23D 23E 1111 1164 1174 A numerical sort does not do the job either. 回答1: If you have LINQ, you can use OrderBy : Regex digitPart = new Regex(@"^\d+", RegexOptions.Compiled); ...

javascript natural sort

我的梦境 提交于 2019-12-17 19:54:40
问题 I have this array : var columnArray = ['columnNumber1','columnNumber6','coulmnNumber7','columnNumber11','columnNumber12']; If I do columnArray.sort(); , it gives me : columnArray: ['columnNumber1','columnNumber11','coulmnNumber12','columnNumber6','columnNumber7'] How can I sort it correctly? 回答1: Try like this: arr = arr.sort(function(a, b) { return +/\d+/.exec(a)[0] - +/\d+/.exec(b)[0]; }); Edit: Fixed it works now, it had a couple errors: http://jsbin.com/iwejik/1/edit 回答2: columnArray.sort