Re: Debugging problems
Re: Debugging problems
- Subject: Re: Debugging problems
- From: glenn andreas <email@hidden>
- Date: Mon, 28 Mar 2005 16:46:35 -0600
On Mar 28, 2005, at 4:15 PM, Michael Mulligan wrote:
Not *exactly* what you want, but seeing you use the heavy artillery
of an NSTask for this... well, you know there's a method
stringByTrimmingCharactersInSet:, don't you? :)
I do, but I simply wanted to turn runs of spaces into one rather than
eliminating them entirely (and tr -s makes this an easy task and
required no extra coding on my part).
Of course, relying on running shell scripts assumes that the underlying
system install includes shells and all the shell tools you use (which,
in the case of a minimum system install, may not).
While there are certainly ways to do everything you need with an
NSScanner, or repeated use of findOccurance and replace, you can also
do something like:
// split the string up at the spaces
NSArray *array = [self componentsSeparatedByString: @" "];
NSEnumerator *e = [array objectEnumerator];
NSMutableArray *filteredItems = [NSMutableArray array];
NSString *currentSubstring;
// go through each substring
while ((currentSubstring = [e nextObject]) != NULL) {
if ([currentSubstring length] != 0)
[filteredItems addObject: currentSubstring]; // add non-empty
substrings
}
return [filteredItems componentsJoinedByString: @" "];
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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