Re: Searching in NSArray
Re: Searching in NSArray
- Subject: Re: Searching in NSArray
- From: KK <email@hidden>
- Date: Fri, 5 Jun 2009 11:56:57 -0400
instead of [s isEqualToString:], you could use [s compare:]
On Fri, Jun 5, 2009 at 11:53 AM, Pierce Freeman <email@hidden
> wrote:
> Hi KK:
>
> I was aware of this method to do so, but can this be done if you needed to
> search for, say, “Good” and wanted it to return Goodbye?
>
> Thanks for your help.
>
>
> On 6/5/09 8:50 AM, "KK" <email@hidden> wrote:
>
> I'm not sure if this is what you're looking for, but Objective-C 2.0 has
> this:
>
> NSArray *a = [NSArray arrayWithObjects:@"Hello",@"Goodbye",nil];
>
> for (NSString *s in a) {
> if ([s isEqualToString:@"Goodbye"]) {
> NSLog(@"it is equal");
> }
> }
>
> And you can have an additional int (or NSInteger) counter to keep track of
> which object it is.
>
> Oh, you could also do [NSArray indexOfObject:]. if it returns NSNotFound,
> it's not in the array.
>
> On Fri, Jun 5, 2009 at 11:36 AM, Pierce Freeman <
> email@hidden> wrote:
>
> Hi Everyone:
>
> I am most likely overlooking this function, but I just can't seem to find
> it
> in the documentation. I am looking for some way to search an NSArray
> listing for one string that is part of multiple objects in the array. This
> search then returns the number of objects that contained that string in it.
> I imagine this would be built into NSArray, so if anyone could steer me in
> the right direction, it would be greatly appreciated!
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com <
> http://lists.apple.com>
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden