Vishwanath Rajendran
Vishwanath Rajendran

Reputation: 23

Sort an NSArray alphabetically by second word

I have a little problem in my project. I have to show the list of brands in alphabetical order. I am getting the list from service which returns in alphabetical order.

The problem is, it is not returning the list of string alphabetically sorted by second word. Sorting by second word should be done programmatically.

For Example:

Beacon, Beat Kangz, Beat Goes On, Behringer

I have to sort above mentioned list alphabetically by both first and second word.

Note: The above mentioned list is already sorted by first word.

Please help me out of it.

Thanks in advance.

Upvotes: 0

Views: 672

Answers (2)

Dipen Panchasara
Dipen Panchasara

Reputation: 13600

Sort Array in Ascending Order or Alphabets

NSArray *arr = [NSArray arrayWithObjects:@"Behringer", @"Beat Goes On", @"Beacon", @"Beat Kangz", @"Apple", @"001" , nil];
NSLog(@"Before %@",arr);
NSArray *sortedArray = [arr sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];    
NSLog(@"After %@",sortedArray);

Upvotes: 2

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

The following sorts the array comparing all the strings/characters....

NSArray *sortedArray=[array sortedArrayUsingSelector(compare:)];

Upvotes: 0

Related Questions