本文介绍了比较两个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个NSArrays,我想要做的是比较两个包含字符串的数组,找到相似之处,再创建第一个数组,所以它们没有相似之处。



只是一个例子。



两个数组:

  NSArray * arrayOne = [NSArray arrayWithObjects:@TD1,@TD2,@TD3,nil]; 
NSArray * arrayTwo = [NSArray arrayWithObjects:@Blah,@String,@TD2,nil];

结果:

 code> NSArray * arrayOne = [NSArray arrayWithObjects:@TD1,@TD2,@TD3,nil]; 

NSArray * arrayOneCopy = [NSArray arrayWithObjects:@TD1,@TD3,nil];
NSArray * arrayTwo = [NSArray arrayWithObjects:@Blah,@String,@TD2,nil];


解决方案
  NSMutableArray * arrayOneCopy = [NSMutableArray arrayWithArray:arrayOne]; 
[arrayOneCopy removeObjectsInArray:arrayTwo];


I have two NSArrays, what I'm looking to do is to compare two arrays which contain strings, find the similarities and create the first array again but so they have no similarities.

Just for an example something like.

Two Arrays:

NSArray *arrayOne = [NSArray arrayWithObjects:@"TD1", @"TD2", @"TD3", nil];
NSArray *arrayTwo = [NSArray arrayWithObjects:@"Blah", @"String", @"TD2", nil];

Outcome:

NSArray *arrayOne = [NSArray arrayWithObjects:@"TD1", @"TD2", @"TD3", nil];

NSArray *arrayOneCopy = [NSArray arrayWithObjects:@"TD1", @"TD3", nil];
NSArray *arrayTwo = [NSArray arrayWithObjects:@"Blah", @"String", @"TD2", nil];
解决方案
NSMutableArray *arrayOneCopy = [NSMutableArray arrayWithArray:arrayOne];
[arrayOneCopy removeObjectsInArray:arrayTwo];

这篇关于比较两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:59