FROM : Johannes Huning
DATE : Sun Mar 02 23:02:06 2008
Or if your're on Leopard using the new enumerator:
NSString *searchFor = @"home";
NSRange range;
for (NSString *string in stringList)
{
range = [word rangeOfString:searchFor];
if (range.location != NSNotFound)
{
NSLog (@"Yay! '%@' found in '%@'.", searchFor, string);
}
}
Correct me if I'm wrong.
_____________
Johannes H.
On Mar 2, 2008, at 10:44 PM, Andrew Merenbach wrote:
> Hi, Tom,
>
> You probably want to use enumerators and something like the
> following code:
>
>> NSEnumerator *e = [array objectEnumerator];
>> NSString *string;
>>
>> while ((string = [e nextObject])) {
>> NSRange range = [string rangeOfString:@"home"];
>> if (range.location != NSNotFound) {
>> NSLog(@"I found home in the string %@", string);
>> }
>> }
>
> The enumerator does what your for-loop does, except that it gives
> you the objects rather than making you use -objectAtIndex:.
> Additionally, the NSRange struct gives you a location, from -
> rangeOfString:, where the found string -- if it isn't the location
> NSNotFound, which may be self-explanatory -- where the string was
> found, and thus tells you whether it was found in the first place.
>
> Cheers,
> Andrew
>
>
>
> On Mar 2, 2008, at 12:31 PM, Tom Jones wrote:
>
>> Hello,
>> I'm fairly new to Cocoa, so please excuse me if I'm not using the
>> right terminology.
>>
>> I have an NSArray which contains String values and I want to loop
>> though it and determine if any of those string contain words I'm
>> looking for. I have tried but have been unsuccessful.
>>
>> Example...
>>
>> unsigned arrayCount = [array count];
>> for(unsigned j = 0; j < arrayCount; j++)
>> {
>> id obj;
>> obj = [array objectAtIndex:j];
>> /* Here is where I'm having trouble
>> I know this is not real :-)
>> if ( [obj inStr:@"home"])
>> {
>> NSLog(@"I found home, %@", obj);
>> }
>> */
>> }
>>
>>
>> I hope the example helps, thanks,
>> tom
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/andrew.<email_removed>
>>
>> This email sent to andrew.<email_removed>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Sun Mar 02 23:02:06 2008
Or if your're on Leopard using the new enumerator:
NSString *searchFor = @"home";
NSRange range;
for (NSString *string in stringList)
{
range = [word rangeOfString:searchFor];
if (range.location != NSNotFound)
{
NSLog (@"Yay! '%@' found in '%@'.", searchFor, string);
}
}
Correct me if I'm wrong.
_____________
Johannes H.
On Mar 2, 2008, at 10:44 PM, Andrew Merenbach wrote:
> Hi, Tom,
>
> You probably want to use enumerators and something like the
> following code:
>
>> NSEnumerator *e = [array objectEnumerator];
>> NSString *string;
>>
>> while ((string = [e nextObject])) {
>> NSRange range = [string rangeOfString:@"home"];
>> if (range.location != NSNotFound) {
>> NSLog(@"I found home in the string %@", string);
>> }
>> }
>
> The enumerator does what your for-loop does, except that it gives
> you the objects rather than making you use -objectAtIndex:.
> Additionally, the NSRange struct gives you a location, from -
> rangeOfString:, where the found string -- if it isn't the location
> NSNotFound, which may be self-explanatory -- where the string was
> found, and thus tells you whether it was found in the first place.
>
> Cheers,
> Andrew
>
>
>
> On Mar 2, 2008, at 12:31 PM, Tom Jones wrote:
>
>> Hello,
>> I'm fairly new to Cocoa, so please excuse me if I'm not using the
>> right terminology.
>>
>> I have an NSArray which contains String values and I want to loop
>> though it and determine if any of those string contain words I'm
>> looking for. I have tried but have been unsuccessful.
>>
>> Example...
>>
>> unsigned arrayCount = [array count];
>> for(unsigned j = 0; j < arrayCount; j++)
>> {
>> id obj;
>> obj = [array objectAtIndex:j];
>> /* Here is where I'm having trouble
>> I know this is not real :-)
>> if ( [obj inStr:@"home"])
>> {
>> NSLog(@"I found home, %@", obj);
>> }
>> */
>> }
>>
>>
>> I hope the example helps, thanks,
>> tom
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/andrew.<email_removed>
>>
>> This email sent to andrew.<email_removed>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Tom Jones | Mar 2, 21:31 | |
| Seth Willits | Mar 2, 22:39 | |
| Andrew Merenbach | Mar 2, 22:44 | |
| j o a r | Mar 2, 23:01 | |
| Johannes Huning | Mar 2, 23:02 | |
| Andrew Merenbach | Mar 2, 23:16 | |
| Chris Hanson | Mar 3, 05:45 | |
| Jens Alfke | Mar 3, 07:50 |






Cocoa mail archive

