如何排序的数字有作为iPhone字符串数组? [英] How to sort array having numbers as string in iPhone?
本文介绍了如何排序的数字有作为iPhone字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能显示的文件:结果
排序最好的方法NSArray的结果
排序有特殊字符数组 - iPhone
块引用>您好,结果
我有数组中,我有数字存储为字符串。结果
如何将这个数组中acsending进行排序?解决方案的NSArray * sortedArray =零;
sortedArray = [oldArray sortedArrayUsingFunction:sortArray方面:NULL];NSInteger的intSort(ID NUM1,NUM2 ID,无效*上下文){ // OR:浮N1 = [NUM1的floatValue]等等 INT N1 = [NUM1的intValue];
INT N2 = [NUM2的intValue];
如果(N1< N2){
返回NSOrderedAscending;
}否则如果(N1> N2){
返回NSOrderedDescending;
}其他{
返回NSOrderedSame;
}
}Possible Duplicates:
best way to sort NSArray
Sort an array with special characters - iPhoneHello,
I have array in which i have numbers stored as string.
How to sort this array in acsending order?解决方案NSArray *sortedArray = nil; sortedArray = [oldArray sortedArrayUsingFunction:sortArray context:NULL]; NSInteger intSort(id num1, id num2, void *context) { // OR: float n1 = [num1 floatValue]; etc. int n1 = [num1 intValue]; int n2 = [num2 intValue]; if (n1 < n2) { return NSOrderedAscending; } else if (n1 > n2) { return NSOrderedDescending; } else { return NSOrderedSame; } }
这篇关于如何排序的数字有作为iPhone字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文