Re: [NSAttributedString attributedStringByTrimming....
Re: [NSAttributedString attributedStringByTrimming....
- Subject: Re: [NSAttributedString attributedStringByTrimming....
- From: Keith Blount <email@hidden>
- Date: Mon, 24 Jul 2006 01:17:58 -0700 (PDT)
Thanks for the replies, much appreciated. I used
Justin and Kirk's suggestion of using -invertedSet,
which makes my code much simpler. My new
implementation is as follows:
- (NSAttributedString
*)attributedStringByTrimmingCharactersInSet:(NSCharacterSet
*)set
{
NSCharacterSet *invertedSet = [set invertedSet];
NSString *str = [self string];
unsigned loc, len;
NSRange range = [str
rangeOfCharacterFromSet:invertedSet];
loc = (range.length > 0) ? range.location : 0;
range = [str rangeOfCharacterFromSet:invertedSet
options:NSBackwardsSearch];
len = (range.length > 0) ? NSMaxRange(range)-loc :
[str length]-loc;
return [self
attributedSubstringFromRange:NSMakeRange(loc,len)];
}
Thanks again,
Keith
--- Kirk Kerekes <email@hidden> wrote:
> I suggest that your implementation might be more
> efficient if instead
> of looking for characters in the trim-set, you were
> to look for
> characters _not_ in the trim-set -- just use
> invertedSet on the trim-
> set. No loops, and then you can just create a single
> NSRange out of
> the results and use that to create your trimmed
> substring.
>
>
>
__________________________________________________
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