natural-sort

Python natural sorting

六眼飞鱼酱① 提交于 2019-11-26 09:47:28
问题 I have some files that need to be sorted by name, unfortunately I can\'t use a regular sort, because I also want to sort the numbers in the string, so I did some research and found that what I am looking for is called natural sorting . I tried the solution given here and it worked perfectly. However, for strings like PresserInc-1_10.jpg and PresserInc-1_11.jpg which causes that specific natural key algorithm to fail, because it only matches the first integer which in this case would be 1 and

Sorting List<String> in C#

白昼怎懂夜的黑 提交于 2019-11-26 08:24:54
问题 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 回答1: 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); }); 回答2: This is called a "natural sort order", and is

How to perform natural sorting?

笑着哭i 提交于 2019-11-26 07:42:07
问题 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? 回答1: I don't think "alphanumeric sort" means what you think it means. In any case, looks like you want mixedsort. > install.packages('gtools

Natural sort order string comparison in Java - is one built in? [duplicate]

半腔热情 提交于 2019-11-26 03:20:47
问题 This question already has answers here : Sort on a string that may contain a number (21 answers) Closed 2 years ago . I\'d like some kind of string comparison function that preserves natural sort order 1 . Is there anything like this built into Java? I can\'t find anything in the String class, and the Comparator class only knows of two implementations. I can roll my own (it\'s not a very hard problem), but I\'d rather not re-invent the wheel if I don\'t have to. In my specific case, I have

Humanized or natural number sorting of mixed word-and-number strings

倖福魔咒の 提交于 2019-11-26 02:56:46
问题 Following up on this question by Sivaram Chintalapudi, I\'m interested in whether it\'s practical in PostgreSQL to do natural - or \"humanized\" - sorting \" of strings that contain a mixture of multi-digit numbers and words/letters. There is no fixed pattern of words and numbers in the strings, and there may be more than one multi-digit number in a string. The only place I\'ve seen this done routinely is in the Mac OS\'s Finder, which sorts filenames containing mixed numbers and words

Natural Sorting algorithm

谁说胖子不能爱 提交于 2019-11-26 02:36:14
问题 How do you sort an array of strings naturally in different programming languages? Post your implementation and what language it is in in the answer. 回答1: Here's how you can get explorer-like behaviour in Python: #!/usr/bin/env python """ >>> items = u'a1 a003 b2 a2 a10 1 10 20 2 c100'.split() >>> items.sort(explorer_cmp) >>> for s in items: ... print s, 1 2 10 20 a1 a2 a003 a10 b2 c100 >>> items.sort(key=natural_key, reverse=True) >>> for s in items: ... print s, c100 b2 a10 a003 a2 a1 20 10

Natural (human alpha-numeric) sort in Microsoft SQL 2005

此生再无相见时 提交于 2019-11-26 01:49:32
问题 We have a large database on which we have DB side pagination. This is quick, returning a page of 50 rows from millions of records in a small fraction of a second. Users can define their own sort, basically choosing what column to sort by. Columns are dynamic - some have numeric values, some dates and some text. While most sort as expected text sorts in a dumb way. Well, I say dumb, it makes sense to computers, but frustrates users. For instance, sorting by a string record id gives something

Natural (human alpha-numeric) sort in Microsoft SQL 2005

纵然是瞬间 提交于 2019-11-26 01:29:51
We have a large database on which we have DB side pagination. This is quick, returning a page of 50 rows from millions of records in a small fraction of a second. Users can define their own sort, basically choosing what column to sort by. Columns are dynamic - some have numeric values, some dates and some text. While most sort as expected text sorts in a dumb way. Well, I say dumb, it makes sense to computers, but frustrates users. For instance, sorting by a string record id gives something like: rec1 rec10 rec14 rec2 rec20 rec3 rec4 ...and so on. I want this to take account of the number, so:

Natural Sort in MySQL

混江龙づ霸主 提交于 2019-11-25 22:59:03
问题 Is there an elegant way to have performant, natural sorting in a MySQL database? For example if I have this data set: Final Fantasy Final Fantasy 4 Final Fantasy 10 Final Fantasy 12 Final Fantasy 12: Chains of Promathia Final Fantasy Adventure Final Fantasy Origins Final Fantasy Tactics Any other elegant solution than to split up the games\' names into their components Title : \"Final Fantasy\" Number : \"12\" Subtitle : \"Chains of Promathia\" to make sure that they come out in the right

Natural Sort Order in C#

不打扰是莪最后的温柔 提交于 2019-11-25 22:15:43
问题 Anyone have a good resource or provide a sample of a natural order sort in C# for an FileInfo array? I am implementing the IComparer interface in my sorts. 回答1: The easiest thing to do is just P/Invoke the built-in function in Windows, and use it as the comparison function in your IComparer : [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] private static extern int StrCmpLogicalW(string psz1, string psz2); Michael Kaplan has some examples of how this function works here, and the changes