{"id":329,"date":"2019-10-07T11:48:04","date_gmt":"2019-10-07T17:48:04","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=329"},"modified":"2019-11-19T09:52:00","modified_gmt":"2019-11-19T16:52:00","slug":"sort-like-finder","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/10\/07\/sort-like-finder\/","title":{"rendered":"Sort like Finder"},"content":{"rendered":"\n<p>Sometimes you want to be able to sort things in the same fashion as the Finder. This method when used as the comparison function for the <em>Arry.Sort( delegate)<\/em> form of sorting will do that<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public Function CompareLikeFinder(firstString as string, secondString as String) as integer\n  #If targetMacOS\n    \/\/ \/\/ \n    \/\/ \/\/ typedef NS_CLOSED_ENUM(NSInteger, NSComparisonResult) {\n    \/\/ \/\/ NSOrderedAscending = -1L,\n    \/\/ \/\/ NSOrderedSame,\n    \/\/ \/\/ NSOrderedDescending\n    \/\/ \/\/ };\n    \/\/ \n    \/\/ \/\/ this gives us \"Finder like\" comparisons\n    \n    \/\/ -[NSString localizedStandardCompare:].\n    Declare Function localizedStandardCompare Lib \"Foundation\" selector \"localizedStandardCompare:\" (string1 As CFStringRef, string2 As CFStringRef) As Integer\n    Return localizedStandardCompare(firstString, secondString)\n    \n    \n  #Else\n    \n    Return StrComp(firstString, secondString, REALbasic.StrCompLexical)\n    \n  #EndIf\n  \n  \n  \nEnd Function\n<\/code><\/pre>\n\n\n\n<p>So with code like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Dim strings() As String\nstrings.append \"file10\"\nstrings.append \"file1\"\nstrings.append \"file2\"\nstrings.append \"file11\"\n\nStrings.sort( AddressOf CompareLikeFinder )<\/code><\/pre>\n\n\n\n<p>You will get<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>file1\nfile2\nfile10\nfile11\n<\/code><\/pre>\n\n\n\n<p>instead of a strictly lexically ordered list<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to be able to sort things in the same fashion as the Finder. This method when used as the comparison function for the Arry.Sort( delegate) form of sorting will do that So with code like You will get instead of a strictly lexically ordered list<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[4,6,3],"class_list":["post-329","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-macos","tag-tips","tag-xojo"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":330,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/329\/revisions\/330"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}