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
Public Function CompareLikeFinder(firstString as string, secondString as String) as integer
#If targetMacOS
// //
// // typedef NS_CLOSED_ENUM(NSInteger, NSComparisonResult) {
// // NSOrderedAscending = -1L,
// // NSOrderedSame,
// // NSOrderedDescending
// // };
//
// // this gives us "Finder like" comparisons
// -[NSString localizedStandardCompare:].
Declare Function localizedStandardCompare Lib "Foundation" selector "localizedStandardCompare:" (string1 As CFStringRef, string2 As CFStringRef) As Integer
Return localizedStandardCompare(firstString, secondString)
#Else
Return StrComp(firstString, secondString, REALbasic.StrCompLexical)
#EndIf
End Function
So with code like
Dim strings() As String
strings.append "file10"
strings.append "file1"
strings.append "file2"
strings.append "file11"
Strings.sort( AddressOf CompareLikeFinder )
You will get
file1
file2
file10
file11
instead of a strictly lexically ordered list