Search code examples
ioscocoansstringnsarray

Manipulation of string array to get +1 at end


I have an array that contains file names as:

NSArray *filename = @[@"anoop", @"anoop100", @"anoop5"];

Now if user creates a new file the new name should be anoop101.

What have I tried:

I sorted the array in that case anoop5 goes at last and incrementing the extracted number gives anoop6, this is not my use case.

I need to sort the strings on the integer part so that anoop100 goes to the end of the list.

Any help?

Edit:

Someone marked it as duplicate of numeric search. In fact its not only numeric search, it has string search as well. So alone makes and incorrect answer and pity for the closer.


Solution

  • filename =[filename sortedArrayUsingSelector:@selector(localizedStandardCompare:)];