I get an array of strings with the following strings, there is a certain patern to the strings
str1 str51 str3 str4 str10 str39 str31 str191
Every string starts with 'str' and has a number appended onto the end of it.
Is there a neath way to sort the array so it lists the strings in order of value
str1 str3 str4 str10 str31 str39 str51 str191
I can see a way to do it by writing some recursive function that will
NSString * firstString = [[strArray objectAtIndex:i].substringFromIndex:3];
NSString * secondString = [[strArray objectAtIndex:i+1].substringFromIndex:3];
if ([firstString intValue] < [secondString intValue])
{
//do nothing they order is correct
}
else
{
//swap the order of the 2 strings in the array
}
But thats very rudimentary code, Is there some mechanism in Objective-C or a nice code trick to handle this sorting better?
Many Thanks, -Code