Re: Get the text from a NSTextView?
Re: Get the text from a NSTextView?
- Subject: Re: Get the text from a NSTextView?
- From: Douglas Davidson <email@hidden>
- Date: Thu, 19 Dec 2002 09:12:40 -0800
On Thursday, December 19, 2002, at 08:24 AM, Lorenzo Puleo wrote:
I have put some text into an NSTextView using:
[myTextView readRTFDFromFile:myFile];
It works well.
Now I want to perform a seach into this text:
foundRange = [myTextView
rangeOfString:@"textToSearch"
options:NSLiteralSearch
range:NSMakeRange(0,[myTextView length])];
But it doesn't work. If instead of myTextView I put a NSString*, it
works.
So, how to get the content of a NSTextView as NSString*?
Since the text could be very long I wouldn't get a duplicate of the
text,
but I would get only a pointer to the text.
[myTextView string] gives the contents of the text view as an NSString.
The actual backing store for the text view is not a string but an
attributed string, in particular an instance of the
NSMutableAttributedString subclass NSTextStorage, and you can obtain
this as [myTextView textStorage]. Given the text storage, you can of
course obtain its underlying non-attributed string via [[myTextView
textStorage] string], but [myTextView string] is a convenience method
for this.
Douglas Davidson
_______________________________________________
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.