开发者

How to match array with array in iphone?

hi i have an array like this:

array1 [00] = 01,KSE
array1 [01] = 04,NCEL
array1 [02] = 06,LSE

I have a second array (codeArray) that has about 50 elements. All elements are '01' or '04' or '06'.

Now i have to compare both arrays & array1 have to return a name (KSE or NCEL or LSE) against the c开发者_JAVA技巧ode so how can i do it? Help plz

Thanx in advance

array1 is a response that i am receiving from server & codeArray is also coming from server thats why both arrays are dynamic & can have any value but all the values in codeArray will exist in array1


Are you using C arrays or NSArray? I will assume NSArray, ok? Sorry I am having a hard time understanding your question.

-(NSArray*)decodeArray:(NSArray*)codeArray keyArray:(NSArray*)array1
{
    NSMutableDictionary * dict = [ NSMutableDictionary dictionary ] ;
    for( NSString * string in array1 )
    {
        NSArray * split = [ string componentsSeparatedByString:@"," ] ;
        [ dict setValue:[ split objectAtIndex:1 ] forKey:[ split objectAtIndex:0 ] ] ;
    }

    NSMutableArray * result = [ NSMutableArray array ] ;
    for( id item in codeArray )
    {
        [ result addObject:[ dict valueForKey:item ] ] ;
    }

    return result ;
}


array1[0] = "01,KSE";
array1[1] = "04,NCEL";
array1[2] = "06,LSE";

if( [codeArray length] == 3 ) {
  if( ([codeArray[0] isEqualToString:@"01"] || [codeArray[0] isEqualToString:@"04"] ||
      [codeArray[0] isEqualToString:@"06"]) && ([codeArray[1] isEqualToString:@"01"] ||
      [codeArray[1] isEqualToString:@"04"] || [codeArray[1] isEqualToString:@"06"]) &&
      ([codeArray[2] isEqualToString:@"01"] || [codeArray[2] isEqualToString:@"04"] ||
      [codeArray[2] isEqualToString:@"06"]) )
           return @"KSE KSE & LSE";

This is all that I can answer on your question ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜