RE: Get the text from a NSTextView?
RE: Get the text from a NSTextView?
- Subject: RE: Get the text from a NSTextView?
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 19 Dec 2002 12:24:21 -0500
What you want is probably:
NSMutableString *searchString = [[myTextView textStorage] mutableString];
foundRange = [searchString
rangeOfString:@"textToSearch"
options:NSLiteralSearch
range:NSMakeRange(0,[searchString length])];
Text views keep their text in text storage objects. NSTextStorage is a
subclass of NSMutableAttributedString (which is where you'll find the
mutableString method). The mutableString of a text view's text storage
object is the "plain text" version of the string displayed in the text view.
You should defininitely review the AppKit text architecture:
http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/Programmin
gTopics/TextArchitecture/index.html#//apple_ref/doc/uid/10000086i
Jonathan
>
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.
>
Thanks.
>
>
--
>
Lorenzo Puleo
>
mailto:email@hidden
>
_______________________________________________
>
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.