ios - sorting NSArray of strings with numbers -


this question has answer here:

i have array contains these string.

@"common area", @"building 1", @"building 2", @"building 3", @"building 4", @"building 10", @"building 14", @"car park", 

i trying sort alphabetically this

areaarray = [areaarray sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)]; 

but displayed like

@"building 1", @"building 10", @"building 14", @"building 2", @"building 3", @"building 4", @"car park", @"common area", 

where displayed as

@"building 1", @"building 2", @"building 3", @"building 4", @"building 10", @"building 14", @"car park", @"common area", 

this code sample magic.

nsarray *stringsarray = @[@"common area", @"building 1", @"building 2", @"building 3", @"building 4", @"building 10", @"building 14", @"car park"];   static nsstringcompareoptions comparisonoptions = nscaseinsensitivesearch | nsnumericsearch | nswidthinsensitivesearch | nsforcedorderingsearch;  nslocale *currentlocale = [nslocale currentlocale];  nscomparator findersortblock = ^(id string1, id string2) {     nsrange string1range = nsmakerange(0, [string1 length]);     return [string1 compare:string2 options:comparisonoptions range:string1range                      locale:currentlocale]; };  nsarray *findersortarray = [stringsarray sortedarrayusingcomparator:findersortblock];  nslog(@"findersortarray: %@", findersortarray); 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -