• 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: [NSAttributedString attributedStringByTrimming....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Finder-like color label menu item in Cocoa?
  • Next by Date: Re: Sending non-string parameters to an AppleScript
  • Previous by thread: Re: how do I run my NSStatusItem app outside of Xcode?
  • Next by thread: How to make a NSToolbarItem for view mode a la Finder?
  • Index(es):
    • Date
    • Thread