Re: Finding paragraphs in NSTextStorage
Re: Finding paragraphs in NSTextStorage
- Subject: Re: Finding paragraphs in NSTextStorage
- From: Jeremy Dronfield <email@hidden>
- Date: Mon, 23 Feb 2004 11:03:14 +0000
You could just do
paragraphsArray = [[myTextView string]
componentsSeparatedByString:@"\n"];
Then your eighth paragraph would be [paragraphsArray objectAtIndex:7].
Whether NSTextStorage -paragraphs is "inefficient" or not depends on
what you're doing with it. It returns, as you know, an array of mutable
attributed strings which include (in addition to character attributes)
paragraph styles. (Try doing NSLog([[myTextStorage paragraphs]
description])) to see just how much stuff is in there. If you don't
need this information, then it's inefficient to load it all into your
array.
-Jeremy
On 23 Feb 2004, at 3:55 am, Joshua Scott Emmons wrote:
Greetings.
I need to be able to calculate the count of the paragraphs in a
textview I have. I also need to be able to say, for example, what the
first sentence of the eighth paragraph is. NSTextStorage has a handy
method called "paragraphs" that does most of the work for me. It
returns an NSArray of all the paragraphs in the attributed string.
However it comes with this disclaimer:
NSTextStorage defines a set of methods... useful for getting and
setting scriptable properties of NSTextStorage objects. In
particular, using the... paragraphs method or its corresponding
setter method is an inefficient way to manipulate the text storage,
since these methods create and return many objects. Instead, use the
text access methods defined by NSMutableAttributedString,
NSAttributedString, NSMutableString, and NSString to perform
character-level manipulation.
I've been kicking it around for three nights now, and I can't figure
out a good way to use the NSAttributedString/NSString classes to sort
out paragraphs. The above documentation makes me think I'm missing
something obvious. Any ideas?
Cheers,
-Josh Emmons
_______________________________________________
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.
_______________________________________________
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.