natural-sort

Alphanumeric sorting with PostgreSQL

放肆的年华 提交于 2019-11-27 11:56:27
In the database, I have various alpha-numeric strings in the following format: 10_asdaasda 100_inkskabsjd 11_kancaascjas 45_aksndsialcn 22_dsdaskjca 100_skdnascbka I want them to essentially be sorted by the number in front of the string and then the string name itself, but of course, characters are compared one by one and so the result of Order by name produces: 10_asdaasda 100_inkskabsjd 100_skdnascbka 11_kancaascjas 22_dsdaskjca 45_aksndsialcn instead of the order I'd prefer: 10_asdaasda 11_kancaascjas 22_dsdaskjca 45_aksndsialcn 100_inkskabsjd 100_skdnascbka Honestly, I would be fine if

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

こ雲淡風輕ζ 提交于 2019-11-27 08:57:33
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, clean and efficient C# snippet which does the same thing? My code currently looks like this: [SuppressUnmanagedCodeSecurity] internal static class SafeNativeMethods { [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] public static extern int StrCmpLogicalW

iOS: natural sort order

*爱你&永不变心* 提交于 2019-11-27 08:19:50
问题 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 回答1: 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:)

Complex sort of field “string - number - string”

纵饮孤独 提交于 2019-11-27 08:18:19
问题 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),

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

眉间皱痕 提交于 2019-11-27 04:49:17
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 Paul Tomblin I asked this exact question (although in Java) and got pointed to http://www.davekoelle.com/alphanum.html which has an algorithm and implementations of it in many languages. Dominic Rodger This is known as natural sorting. There's an algorithm here that looks promising. Be careful of

Sorting List<String> in C#

人盡茶涼 提交于 2019-11-26 22:41:20
How to sort a List based on the item's integer value The list is like "1" "5" "3" "6" "11" "9" "NUM1" "NUM0" The result should be like "1" "3" "5" "6" "9" "11" "NUM0" "NUM1" is there any idea to do this using LINQ or Lambda expression? Thanks in advance How about: list.Sort((x, y) => { int ix, iy; return int.TryParse(x, out ix) && int.TryParse(y, out iy) ? ix.CompareTo(iy) : string.Compare(x, y); }); This is called a "natural sort order", and is usually employed to sort items like those you have, like filenames and such. Here's a naive (in the sense that there are probably plenty of unicode

How to perform natural sorting?

我与影子孤独终老i 提交于 2019-11-26 20:43:19
Is there a natural sort for R? Say I had a character vector like so: seq.names <- c('abc21', 'abc2', 'abc1', 'abc01', 'abc4', 'abc201', '1b', '1a') I'd like to sort it aphanumerically, so I get back this: c('1a', '1b', 'abc1', 'abc01', 'abc2', 'abc4', 'abc21', 'abc201') Does this exist somewhere, or should I start coding? I don't think "alphanumeric sort" means what you think it means. In any case, looks like you want mixedsort . > install.packages('gtools') [...] > require('gtools') Loading required package: gtools > n [1] "abc21" "abc2" "abc1" "abc01" "abc4" "abc201" "1b" "1a" > mixedsort(n)

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

十年热恋 提交于 2019-11-26 17:47:27
问题 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, clean and efficient C# snippet which does the same thing? My code currently looks like this: [SuppressUnmanagedCodeSecurity] internal static class

Alphanumeric sorting with PostgreSQL

不打扰是莪最后的温柔 提交于 2019-11-26 15:48:24
问题 In the database, I have various alpha-numeric strings in the following format: 10_asdaasda 100_inkskabsjd 11_kancaascjas 45_aksndsialcn 22_dsdaskjca 100_skdnascbka I want them to essentially be sorted by the number in front of the string and then the string name itself, but of course, characters are compared one by one and so the result of Order by name produces: 10_asdaasda 100_inkskabsjd 100_skdnascbka 11_kancaascjas 22_dsdaskjca 45_aksndsialcn instead of the order I'd prefer: 10_asdaasda

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

筅森魡賤 提交于 2019-11-26 11:22:57
问题 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 回答1: I asked this exact question (although in Java) and got pointed to http://www.davekoelle.com/alphanum.html which has an algorithm and implementations of it in many languages. 回答2: Several natural