Best way to create string from an array of dictionaries?
Best way to create string from an array of dictionaries?
- Subject: Best way to create string from an array of dictionaries?
- From: Keith Blount <email@hidden>
- Date: Mon, 24 Jul 2006 03:25:29 -0700 (PDT)
Hello,
In my app the user can create an array of keywords for
each document created and then search by these
keywords. The keywords are entered via a table view
with an NSArrayController, but the search relies on
searching strings. For the search, I therefore need to
convert the array of keywords into a plain string.
Obviously, NSArray has a great method for this:
-componentsJoinedByString:
However, each component of my -keywords array is an
NSDictionary. Each dictionary just contains a keyword
string for the key "keyword" - there are no other
keys. Really, it could be a straightforward array
holding the strings directly rather than dictionaries,
were it not for the fact that NSArrayController relies
on KVC, and thus the components of my array must be
dictionaries to work in my bound table view.
This makes creating a string for my search methods a
little more difficult. With the dictionaries in my
keywords array, if I use
componentsJoinedByString:@"/n", I get something like
this:
{keyword = blah; }
{keyword = something; }
{keyword = "something else"; }
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.
Many thanks in advance,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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