how to remove duplicate value in NSMutableArray

前端 未结 6 1390
离开以前
离开以前 2021-01-24 22:32

i\'m scanning wifi info using NSMutableArray, but there are few duplicate values appear, so i try to use following code but still getting the duplicate values,

         


        
6条回答
  •  既然无缘
    2021-01-24 23:01

    Here is the code of removing duplicates values from NSMutable Array..it will work for you. myArray is your Mutable Array that you want to remove duplicates values..

    for(int j = 0; j < [myArray count]; j++){
        for( k = j+1;k < [myArray count];k++){
            NSString *str1 = [myArray objectAtIndex:j];
            NSString *str2 = [myArray objectAtIndex:k];
            if([str1 isEqualToString:str2])
                [myArray removeObjectAtIndex:k];
           }
    }
    // Now print your array and 
    

提交回复
热议问题