---
title: "Finding a NSString in an Array in a Master Array"  
description: "Finding a NSString in an Array in a Master Array"  
author: "Anonymous User"  
published: 2015-07-15  
updated: 2015-07-15  
canonical: https://www.mindstick.com/forum/23341/finding-a-nsstring-in-an-array-in-a-master-array  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Finding a NSString in an Array in a Master Array

I have a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) called alpha.

## alpha= @"pie"

I have 3 [arrays](https://www.mindstick.com/articles/11955/arrays-and-its-limitations) that were added into a master [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) called "ALL WORDS"

```
array 1 = [nsarray alloc]initwithobjects @"cake", @"donut"];array 2 = [nsarray alloc]initwithobjects @"cream", @"pie"];array 3 = [nsarray alloc]initwithobjects @"rice", @"flour"];      allwords = [NSMutableArray array];    [allwords addObjectsFromArray:array1];    [allwords addObjectsFromArray:array2];    [allwords addObjectsFromArray:array3];So now I am doing a for loop like this for (int i = 0; i < [allWords count]; i++) {        NSString *takestring =[allWords objectAtIndex:i];        if ( [takestring is equal to alpha]) {           //tell which array alpha or takestring came from????                    }         }
```

My [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) is, how can I determine which array the pie came from. in the app [people](https://www.mindstick.com/news/2295/more-people-need-to-monitor-this-crucial-metric-for-heart-health) might have new words that I might not know, but i want to be able to [detect](https://www.mindstick.com/forum/1906/detect-when-cd-drive-was-closed) where that string what array is it from?

Anybody knows how I can do this??

## Replies

### Reply by Tarun Kumar

You should not merge array as per your description. instead you should use something like below.

```
@interface aViewController ()@property (nonatomic, strong) NSMutableArray *allwords;@end@implementation aViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view from its nib.    NSArray *array1 = [[NSArray alloc] initWithObjects:@"cake",@"donut", nil];    NSArray *array2 = [[NSArray alloc] initWithObjects:@"cream", @"pie", nil];    NSArray *array3 = [[NSArray alloc] initWithObjects:@"rice", @"flour", nil];    self.allwords = [[NSMutableArray alloc] initWithObjects:array1, array2,                    array3, nil];    [self findMyArray:self.allwords];}- (void) findMyArray:(id)array {   if ([array isKindOfClass:[NSArray class]] ||       [array isKindOfClass:[NSMutableArray class]]) {          for (NSArray *temp in array) {              for (NSString *str in temp) {                  if ([str isEqualToString:@"pie"]) {                     // define @"pie" as per your requirement                     NSLog(@"THE ARRAY WHICH CONTAIN PIE IS %@", temp);                  }              }          }   }}@end
```

Using this you can simply find your array which contains specific string.


---

Original Source: https://www.mindstick.com/forum/23341/finding-a-nsstring-in-an-array-in-a-master-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
