iphone - Sort strings having numbers and characters -
i have set of strings this.
1 wednesday, 3 monday, 1 2 tuesday now need sort these considering letters. results be
3 monday, 1 2 tuesday, 1 wednesday the strings sorted considering substrings (wednesday, monday, tuesday) got result. how can ?
use compareoptions, remove kcfcomparenumerically in options.
see next url: sorting strings
or try this:
#import <foundation/foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { nsarray *stringsarray = [nsarray arraywithobjects: @"string 1", @"string 21", @"string 12", @"string 11", @"string 02", nil]; static nsstringcompareoptions comparisonoptions = nscaseinsensitivesearch | nswidthinsensitivesearch | nsforcedorderingsearch; nslocale *currentlocale = [nslocale currentlocale]; nscomparator findersort = ^(id string1, id string2) { nsrange string1range = nsmakerange(0, [string1 length]); return [string1 compare:string2 options:comparisonoptions range:string1range locale:currentlocale]; }; nsarray* sortedarray = [stringsarray sortedarrayusingcomparator:findersort]; nslog(@"findersort: %@", sortedarray); } return 0; }
Comments
Post a Comment