嗨我有两条线。
阵列A:
arrProductSelection = [[NSArray alloc]initWithObjects:@"English",@"German",@"Russian",@"Chinese",@"Spanish",@"French",@"French",@"French",@"French",@"French",@"French",@"French",@"French",nil];阵列B:
arrProductSelectionB = [[NSArray alloc]initWithObjects:@"deselcted",@"selected",@"selected",@"selected",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",nil];我需要比较两个数组,并从数组A中获得值,方法是将数组B与所选的值进行比较。也就是说,我应该把德语、汉语和俄语用逗号作为nsstring。
发布于 2016-09-28 11:08:47
试试这个:
NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
NSArray *arrProductSelection = [[NSArray alloc]initWithObjects:@"English",@"German",@"Russian",@"Chinese",@"Spanish",@"French",@"French",@"French",@"French",@"French",@"French",@"French",@"French",nil];
NSArray *arrProductSelectionB = [[NSArray alloc]initWithObjects:@"deselcted",@"selected",@"selected",@"selected",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",nil];
for(int i = 0; i< arrProductSelectionB.count-1;i ++) {
if ([arrProductSelectionB[i] isEqualToString:@"selected"]) {
[arrSelected addObject:arrProductSelection[i]];
}
}
NSString *strSelected = [arrSelected componentsJoinedByString:@","];
NSLog(@"%@", strSelected);//output: German,Russian,Chinese发布于 2016-09-28 11:10:52
首先,我将确保两个数组具有相同的安全计数器,比如
if (arrProductSelection.count == arrProductSelectionB) {
//than all you need is one for cycle something like :
for (int i = 0; i < arrProductionSelectionB.count; i++) {
if ([arrProductionSelectionB[i] isEqualToString: @"selected"]) {
do something magically with arrProductSelection[i];
}
}
}发布于 2016-09-28 11:19:09
如果您可以使这种类型的数组,然后管理容易。
(
{
flag = deselcted;
name = English;
},
{
flag = selected;
name = German;
},
{
flag = deselcted;
name = Russian;
},
{
flag = deselcted;
name = Chinese;
}
)==>数组(字典),(字典),.
https://stackoverflow.com/questions/39745602
复制相似问题