• 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: Get the text from a NSTextView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Get the text from a NSTextView? (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: customizing text layout - where to start?
  • Next by Date: Re: Shared frameworks, not in an app wrapper (Was: Frameworks in the app wrapper)
  • Previous by thread: Re: Get the text from a NSTextView?
  • Next by thread: FW: Get the text from a NSTextView?
  • Index(es):
    • Date
    • Thread