Re: Best way to create string from an array of dictionaries?
Re: Best way to create string from an array of dictionaries?
- Subject: Re: Best way to create string from an array of dictionaries?
- From: James Bucanek <email@hidden>
- Date: Mon, 24 Jul 2006 06:53:29 -0700
Keith Blount wrote on Monday, July 24, 2006:
>For now, I have done this:
>
>NSMutableString *str = [NSMutableString
>stringWithString:[keywords
>componentsJoinedByString:@"\n"]];
> [str replaceOccurrencesOfString:@"keyword"
>withString:@"" options:0 range:NSMakeRange(0,[str
>length])];
>
>This gets rid of all of the occurrences of "keyword"
>in the search string but obviously there are still the
>junk characters. This is probably fine for my needs,
>but I wondered if there was an easier or more efficent
>way to go about this.
Why not a simple loop?
(Typed in e-mail)
NSMutableString* s = [NSMutableString string];
NSEnumerator* e = [keywords objectEnumerator];
id dictionary;
while ( (dictionary=[e nextObject])!=nil )
[s appendFormat:@"\n%@",[dictionary objectForKey:@"keyword"]];
(using a for loop and two more lines of code and you could eliminate the superfluous \n)
Actually, I can't quit figure out why you just don't iterate through the array performing the match on each string. Surely, you don't want a search string to match across two keywords.
NSEnumerator* e = [keywords objectEnumerator];
id dictionary;
while ( (dictionary=[e nextObject])!=nil )
if ([[dictionary objectForKey:@"keyword"] rangeOfString:@"search_string"].location!=NSNotFound)
return (dictionary);
return (nil);
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden