繁体   English   中英

NSMutableArray包含对象多个字符串

[英]NSMutableArray Contains Object multiple strings

我得到了数组的结果,像这样

shape= { 1,2,3,4,5,6,7}
if([shapes containsObject:@"10"])
{
        ...
}
else if([shapes containsObject:@"1"])
{
       ...
}

如果我想选择多个包含第二次获得数组值的Contain的对象,第二次获得类似于5,6,7的数组,我想使用5,6,7的所有值怎么做?

尝试这个

shape = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7",nil];

if ([shape containsObject: @"10"]) // YES
 {
// Do something
 }

另一种选择

for (NSString* str in shape) 
{
if ([str isEqualToString:@"10"])
  {
   }

 else if ([str isEqualToString:@"1"])
  {
   }
 }

如果要比较多个值,可以尝试这样:

NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];
if([shapes containsObject:@10] || [shapes containsObject:@5] || [shapes containsObject:@7])
{
    NSLog(@"found");
}
else
{
    NSLog(@"Not found");
}

注意:-如果使用objective-c NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];的文字,则您的数组格式应类似于此NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM