natural-sort

IComparer for natural sorting [duplicate]

﹥>﹥吖頭↗ 提交于 2019-11-29 04:18:35
This question already has an answer here: Natural Sort Order in C# 16 answers 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. If you have LINQ, you can use OrderBy : Regex digitPart = new Regex(@"^\d+", RegexOptions.Compiled); ... myList.OrderBy(x => int.Parse(digitPart.Match(x).Value)) John Arlen The easiest is to wrap the Win32 API call as explained in https:/

How to compare version string (“x.y.z”) in MySQL?

一笑奈何 提交于 2019-11-29 03:40:26
I have firmware version strings into my table (like "4.2.2" or "4.2.16") How can I compare, select or sort them ? I cannot use standard strings comparison : "4.2.2" is a seen by SQL greater than "4.2.16" As version strings, I would like 4.2.16 to be greater than 4.2.2 I would like to consider that firmware version can have chars in them : 4.24a1, 4.25b3 ... for this, usually, the subfield with chars has a fixed length. how to proceed ? If all your version numbers look like any of these: X X.X X.X.X X.X.X.X where X is an integer from 0 to 255 (inclusive), then you could use the INET_ATON()

Complex sort of field “string - number - string”

我的未来我决定 提交于 2019-11-28 14:09:41
Basically, I am trying to sort a table by its name. The table is relatively big, but I am posting only one column, for sake of example. The Column is Station below Station === ANTIL WELL 1 ANTIL WELL 2 BASELINE & CALIFORNIA WELL EPA WELL 6 EPA WELL 7 EPA WELL 108 EPA WELL 109 EPA WELL 110 EPA WELL 111 EPA WELL 112 EPA WELL 108S The sort above was achieved by me trying this: order by left(station,LEN(station) -PATINDEX('%[^0-9]%',REVERSE(station))+1) ,CONVERT(int,REVERSE(LEFT(REVERSE(station), PATINDEX('%[^0-9]%',REVERSE(station)) - 1))) However, I just can't sort that EPA WELL 108S. I need it

iOS: natural sort order

依然范特西╮ 提交于 2019-11-28 14:02:13
I have an app for iOS that uses Core Data to save and retrieve data. How would I fetch data sorted by a field of NSString type in natural sort order ? Right now the result is: 100_title 10_title 1_title I need: 1_title 10_title 100_title You can use localizedStandardCompare: as selector in the sort descriptor for the Core Data fetch request, for example NSSortDescriptor *titleSort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedStandardCompare:)]; [fetchRequest setSortDescriptors:[titleSort]]; Swift 3: let titleSort = NSSortDescriptor(key: "title",

javascript natural sort

孤街浪徒 提交于 2019-11-28 11:47:25
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? 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 columnArray.sort(function(a,b) { return parseInt(a.match(/\d+/)[0],10) - parseInt(b.match(/\d+/)[0],10); }); demo There is a npm

Natural sort with SQL Server

允我心安 提交于 2019-11-28 10:37:17
问题 I want to convert the order of the values with column name PTNT_VST_CSNO from the following : VMIP1 VMIP10 VMIP11 VMIP2 VMIP20 VMIP21 VMIP3 VMIP31 VMIP32 VMIP5 VMIP6 VMIP7 VMIP8 VMIP9 VMOP10 VMOP11 VMOP12 VMOP3 VMOP30 VMOP31 VMOP32 VMOP4 VMOP40 VMOP41 VMOP42 VMOP43 VMOP7 VMOP70 VMOP71 VMOP8 VMOP9 to: VMIP1 VMIP2 VMIP3 VMIP5 VMIP6 VMIP7 VMIP8 VMIP9 VMIP10 VMIP11 VMIP20 VMIP21 VMIP31 VMIP32 VMOP3 VMOP4 VMOP7 VMOP8 VMOP9 VMOP10 VMOP11 VMOP12 VMOP30 VMOP31 VMOP32 VMOP40 VMOP41 VMOP42 VMOP43

array_multisort with natural sort

一个人想着一个人 提交于 2019-11-28 09:29:37
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 sorted naturally. Basically that will be array_multisort with natural sort. I found many solutions

Sort string as number in sql server

青春壹個敷衍的年華 提交于 2019-11-28 07:25:54
问题 I have a column that contains data like this. dashes indicate multi copies of the same invoice and these have to be sorted in ascending order 790711 790109-1 790109-11 790109-2 i have to sort it in increasing order by this number but since this is a varchar field it sorts in alphabetical order like this 790109-1 790109-11 790109-2 790711 in order to fix this i tried replacing the -(dash) with empty and then casting it as a number and then sorting on that select cast(replace(invoiceid,'-','')

How to do sorting on irregular Alphanumeric data in postgres sql

南楼画角 提交于 2019-11-28 05:42:22
问题 I have the following sample data for a particular column symbol for sample table. (Update:) The data is not in a regular pattern. Number may occur at any place in between characters. symbol COL4A1 COL4A3 COL8A2 COL2A1 COL12A1 COL12A1 COL16A1 COL19A1 I need to sort the this data on database level. I used the following query: select symbol from sample order by symbol asc Result is follows: COL12A1 COL12A1 COL16A1 COL19A1 COL2A1 COL4A1 COL4A3 COL8A2 But I need to get the order in the following

How to compare version string (“x.y.z”) in MySQL?

被刻印的时光 ゝ 提交于 2019-11-27 17:45:39
问题 I have firmware version strings into my table (like "4.2.2" or "4.2.16") How can I compare, select or sort them ? I cannot use standard strings comparison : "4.2.2" is a seen by SQL greater than "4.2.16" As version strings, I would like 4.2.16 to be greater than 4.2.2 I would like to consider that firmware version can have chars in them : 4.24a1, 4.25b3 ... for this, usually, the subfield with chars has a fixed length. how to proceed ? 回答1: If all your version numbers look like any of these: