RE: componentsSeparatedByString:
RE: componentsSeparatedByString:
- Subject: RE: componentsSeparatedByString:
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Wed, 29 Oct 2003 17:02:02 -0500
>
My method looks like that:
>
>
NSMutableArray *tmpArray;
>
NSArray *myFunctionResult;
>
>
myFunctionResult = [NSMutableArray array];
>
>
while( (myString = some method result) != nil )
>
{
>
#ifdef VERSION_THAT_DOESNT_WORK
>
tmpArray = [[myString componentsSeparatedByString:aString]
>
mutableCopy];
>
[tmpArray removeObject:anotherString];
>
[myFunctionResult addObjectsFromArray:tmpArray];
>
[tmpArray release];
>
#else
>
tmpArray = [[NSMutableArray alloc]
>
initWithArray:[myString componentsSeparatedByString:aString]
>
copyItems:YES];
>
[tmpArray removeObject:anotherString];
>
[myFunctionResult addObjectsFromArray:tmpArray];
>
[tmpArray release];
>
#endif
>
}
>
>
return myFunctionResult;
You are removing anotherString from tmpArray. Could that be your problem?
>
> Are you really sure you are accessing the same strings every time?
>
> Are you
>
> really sure they don't start out empty? Try to figure out exactly
>
> when the
>
> value changes (using the debugger of course).
>
>
I spent a couple of hours yesterday doing that. In fact, my class is an
>
NSTextFormatter subclass which transforms a string into an array (for
>
Google-like search, where each word is transformed into an item except
>
for words enclosed by double quotes which are seen as a single "word")
>
and vice versa.
componentsSeparatedByString only recognizes one delimiter at a time. Unless
you are doing something else (recombining quoted search terms, maybe), each
word will be a separate object in the array, regardless of any quote marks.
>
The built array is then used by some object which gets
>
it with [theFormattedTextField objectValue] and performs the search.
This doesn't seem like a job for a formatter. It feels more like a delegate
or a controller should peek at the textfield and do the search.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.