views:

78

answers:

1

I have a NSMutableArray that I need to search for a string and return the key in the array where the string was found. So for example if I'm searching "ipod" and it's the 4th in the array, it would return 3 or whatever position the string is in. What's the best way to do this?

+2  A: 
return [theArray indexOfObject:@"ipod"];

Reference: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:.

Note that NSMutableArray inherits from NSArray, so any NSArray methods can be used on NSMutableArray too.

KennyTM
Would you know how to do it with objects within the array? For example I'm using the XMLParser and would want to know where the word iPod is located in a sub object.
Raphael Caixeta