0

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 code 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

6
  • What do you want to do ? Commented May 5, 2011 at 6:27
  • i want to compare both arrays & if codeArray have 3 elements & they are 01 01 & 06 then array1 should return KSE KSE & LSE. Commented May 5, 2011 at 6:33
  • array1[0] = ?? What value is 01,KSE is this string ??? Commented May 5, 2011 at 6:44
  • 1
    Question does not make any sense. Also, who is plz and how can I help him? Commented May 5, 2011 at 6:50
  • @vito u r right array1[0] = 01,KSE & array1 [1] = 04,NCEL. infect i got a string that was @"01,KSE;04,NCEL;06,LSE" then i separate it & saved it in an array Commented May 5, 2011 at 6:57

2 Answers 2

1

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 ;
}
Sign up to request clarification or add additional context in comments.

3 Comments

you got the point what i need. but array1 can be changed & can have different values, not only these 3 values. Now we have to make it generic
:D thanx nielsbot for help you got my problem that is what i am looking for. So nice of you & COOL :)
since I did your homework for you you should check my answer :)
0
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 ...

3 Comments

array1 can have different codes not the same codes every time
No matter what values it can have because I compare codeArray values and return KSE KSE & LSE
I mean that in array1 values can be increased there can also come "GSE" "DSE" with some codes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.