如何比较2 NSMutableArray和获取不同数值的值 [英] how to compare 2 NSMutableArray and get different number of value

查看:148
本文介绍了如何比较2 NSMutableArray和获取不同数值的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较2个NSMutableArray值,并检查哪个indexPath不同,并将这些索引号存储在一个数组中。
例如我有这些NSMutableArray:

I want compare 2 NSMutableArray values and check which indexPath is different and store this numbers of index in one array. for example I have these NSMutableArray :

NSMutableArray *a = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil];
NSMutableArray *b = [[NSMutableArray alloc]initWithObjects:@"11",@"2",@"5",@"3",@"53",@"6", nil];

,我想将这两个NSMutableArray索引与索引进行比较这些NSMutableArrays中的数组索引是不同的。例如在两个NSMutableArray上,这个索引是不同的(0,2,3,4),我想把这个值存储在某个Array中。

and I want to compare these two NSMutableArray index to index (compare value to value) and tell me that which index of array in these NSMutableArrays is different. for example in two NSMutableArray on top this index is different (0,2,3,4) and I want store this values in certain Array.

推荐答案

NSMutableArray* differentIndex;
differentIndex = [[NSMutableArray alloc] init];
for(int i = 0 ; i < [a count]; i++) {
    if(i < [b count]){
        if(![b[i] isEqual:a[i]]){
             [differentIndex addObject:[NSNumber numberWithInt:i]];
         }
    } else {
        [differentIndex addObject:[NSNumber numberWithInt:i]];
    }
}

现在你的differentIndex包含数组中所有不同的索引。 :)

Now your differentIndex contains all the different index in the arrays. :)

这篇关于如何比较2 NSMutableArray和获取不同数值的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆