• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to create string from an array of dictionaries?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Best way to create string from an array of dictionaries?
      • From: Keith Blount <email@hidden>
References: 
 >Best way to create string from an array of dictionaries? (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: What is serializaton?
  • Next by Date: Re: writing huge C-array to a file
  • Previous by thread: Best way to create string from an array of dictionaries?
  • Next by thread: Re: Best way to create string from an array of dictionaries?
  • Index(es):
    • Date
    • Thread