次の文字列を含む文字列の配列を取得します。文字列には特定のパターンがあります
str1 str51 str3 str4 str10 str39 str31 str191
すべての文字列は「str」で始まり、末尾に数字が追加されます。
値の順に文字列を一覧表示するように配列を並べ替える適切な方法はありますか
str1 str3 str4 str10 str31 str39 str51 str191
再帰関数を書くことでそれを行う方法を見ることができます
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
}
しかし、それは非常に初歩的なコードです。Objective-Cには、この並べ替えをより適切に処理するためのメカニズムや優れたコードトリックがありますか?
どうもありがとう、-コード