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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -