title: NSMutableArray for loop
body: <p>My for loops don't seem to be doing what I'm asking of them.  I'm trying to do a count if it's not equal to a space and the other for loop I'm trying to remove a object if it equals a space.  Neither seem to be working cause my NSLOG tell me it's still counting the spaces and also not removing them.  Any help would be greatly appreciated.</p>
  
  <pre><code>NSMutableArray *a1 = [[NSMutableArray alloc] init];
  // Take address and break into array by colon
  
  if ([str rangeOfString:@"::"].location == NSNotFound)
  {
  
      NSLog(@"Double Colon not found");
  }
  else 
  {
  
      a1 = [[display.text componentsSeparatedByString:@":"]mutableCopy];
      //Separate string by colon
      NSLog(@"Separated string by colon: %@",a1);
  
      //count non blank segments
      for (item in a1) {
          if (item != @""){
              numofSeg = numofSeg + 1;
  
              needSeg = 8 - numofSeg;
              NSLog(@"%d",needSeg);
              }
  
      }
  
  
  
      while (needSeg &gt; 0) {
  
          NSUInteger index = [a1 indexOfObject:@""];
          if (index != NSNotFound) {
              [a1 insertObject:@"0000" atIndex:index];
              needSeg = needSeg - 1;
  
          }
      }
      for (item in a1) {
          if (item == @"") {
              //remove blank spaces from list
              [a1 removeObject:item];
          }
      }
  }
  
  //Join objects back into a string separted by colon.
  NSString *join = [a1 componentsJoinedByString:@":"];
  NSLog(@"Join array into String: %@",join);
  </code></pre>
  
  <p>Output below.  When I join the array back together it should equal 8 segments but only 6 show.  That telling me it's counting the two spaces from when I separated the double colon.</p>
  
  <pre><code>2012-10-01 19:50:52.430 IPv6[1287:c07] Separated string by colon: (
  2002,
  0000,
  "",
  ""
  )
  2012-10-01 19:50:52.432 IPv6[1287:c07] 7
  2012-10-01 19:50:52.433 IPv6[1287:c07] 6
  2012-10-01 19:50:52.434 IPv6[1287:c07] 5
  2012-10-01 19:50:52.435 IPv6[1287:c07] 4
  2012-10-01 19:50:52.435 IPv6[1287:c07] Join array into String:       2002:0000:0000:0000:0000:0000::
  </code></pre>