首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何比较两种不同值的射线?

如何比较两种不同值的射线?
EN

Stack Overflow用户
提问于 2016-09-28 11:01:40
回答 4查看 77关注 0票数 1

嗨我有两条线。

阵列A:

代码语言:javascript
复制
 arrProductSelection = [[NSArray alloc]initWithObjects:@"English",@"German",@"Russian",@"Chinese",@"Spanish",@"French",@"French",@"French",@"French",@"French",@"French",@"French",@"French",nil];

阵列B:

代码语言:javascript
复制
arrProductSelectionB = [[NSArray alloc]initWithObjects:@"deselcted",@"selected",@"selected",@"selected",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",@"deselcted",nil];

我需要比较两个数组,并从数组A中获得值,方法是将数组B与所选的值进行比较。也就是说,我应该把德语、汉语和俄语用逗号作为nsstring。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-09-28 11:08:47

试试这个:

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2016-09-28 11:10:52

首先,我将确保两个数组具有相同的安全计数器,比如

代码语言:javascript
复制
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];
     }
   }
}
票数 0
EN

Stack Overflow用户

发布于 2016-09-28 11:19:09

如果您可以使这种类型的数组,然后管理容易。

代码语言:javascript
复制
(
        {
        flag = deselcted;
        name = English;
    },
        {
        flag = selected;
        name = German;
    },
        {
        flag = deselcted;
        name = Russian;
    },
        {
        flag = deselcted;
        name = Chinese;
    }
)

==>数组(字典),(字典),.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39745602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档