Sorting array containing strings in objective c
        Posted  
        
            by jakob
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jakob
        
        
        
        Published on 2010-05-08T13:42:38Z
        Indexed on 
            2010/05/08
            13:48 UTC
        
        
        Read the original article
        Hit count: 398
        
Hello experts!
I have an array named 'names' with strings looking like this: ["name_23_something", "name_25_something", "name_2_something"]; Now I would like to sort this array in ascending order so it looks like this: ["name_25_something", "name_23_something", "name_2_something"];
I guess that should start of with extracting the numbers since I want that the sorting is done by them:
for(NSString *name in arr) {
    NSArray *nameSegments = [name componentsSeparatedByString:@"_"];
    NSLog("number: %@", (NSString*)[nameSegments objectAtIndex:1]);     
}
I'm thinking of creating a dictionary with the keys but I'm not sure if that is the correct objective-c way, maybe there some some methods I could use instead? Could you please me with some tips or example code how this sorting should be done in a proper way.
Thank you
© Stack Overflow or respective owner