title: Collection Enumeration Searching for Strings in Order
body: <p>I have an array that contains 500 strings (<code>NSString</code>), each represents only one character (ex: <code>@"H"</code>) which I will loop through from start to end.</p>
  
  <p>Among these strings there are for example strings such as <code>@"H"</code>, <code>@"e"</code>, <code>@"l"</code>, <code>@"l"</code>, <code>@"o"</code>.</p>
  
  <p>They are <strong><em>definitely</em></strong> in the array but the order is unknown. </p>
  
  <p>I would like to loop through the array from start to end and would like to print out
  "Hello" with no repeats. Just once. And the string <code>@"H"</code> has to occur first before "ello".</p>
  
  <p>So when the first <code>@"H"</code> occurs I would start to look for the rest namely "ello" and print them out. </p>
  
  <p>Been thinking about this for the past hour and I could not come anything unfortunately except that:</p>
  
  <p>Perhaps there are some condition such as <code>NSPredicate</code> etc where I could first find the index numbers of these strings in order before the loop takes place. And so I could just print them out without having to check as I loop through the array and thus making use of a bunch of <code>if-else</code>. </p>
  
  <p><em><strong>For example:</em></strong></p>
  
  <pre><code>NSArray *indexesThatMatchTheStrings = [......(condition =&gt; @"H", @"e", @"l", @"l", @"o").....]'
  </code></pre>
  
  <p>And <code>indexesThatMatchTheStrings</code> would contain the matching indexes. If the condition isn't satisfied, then I would know beforehand I don't have to print them out. Again, "H", "e", "l", "l", "o" are there within the array, but the order matters.</p>
  
  <p>Is there some operation like this in collections? I am open to any kind of collections and algorithms (i.e. <code>NSSet</code>, <code>NSArray</code>, <code>NSDictionary</code> etc). Even methods in <code>C</code> (bit shifts, structs, memory compare, etc). Some thing fast and light-weight. </p>
  
  <p><em><strong>Addendum:</em></strong></p>
  
  <p>To generalize a bit the use case:</p>
  
  <p>Are there any ways or method provided by the framework with which we could set a test condition for a collection such as an array, a dictionary or a set, where we could find out whether some things are in fact within them based on a particular condition (in my case here: the h e l l o sequence), so that we could minimize the looping + comparing overhead? Or even avoid the need to loop + search altogether, since we know the search condition is not met for the collection? </p>