• 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: NSString of selected text in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString of selected text in NSTextView


  • Subject: Re: NSString of selected text in NSTextView
  • From: Mark Gallegly <email@hidden>
  • Date: Sat, 07 Nov 2009 18:06:46 -0800
  • Thread-topic: NSString of selected text in NSTextView

Here is one:

-(NSString*) getSelectedTextInTextView:(NSTextView*)theTextView
{
    NSRange range = [theTextView selectedRange];
    NSData* rtfData = [theTextView RTFFromRange: range];
    NSAttributedString* aStr = [[NSAttributedString alloc]
        initWithRTFData:rtfData documentAttributes: NULL];
    NSString* str = [aStr string];
    return str;
}


On 11/7/09 5:57 PM, "Todd Heberlein" <email@hidden> wrote:

> This seems like a simple task, but it has become a series of steps. Am
> I missing a simple method that will do this?
>
> I have a Text View and want to get the selected text in an NSString
> form. I can get an NSString for the entire NSTextView (-string), but
> to get the string for just the selected text seems to take multiple
> steps:
>
> NSRange range = [theTextView selectedRange];
> NSData* rtfData = [theTextView RTFFromRange: range];
> NSAttributedString* aStr = [[NSAttributedString alloc]
> initWithRTFData:rtfData documentAttributes: NULL];
> NSString* str = [aStr string];
>
> Is there a method that combines all these steps?
>
> Thanks,
>
> Todd
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSString of selected text in NSTextView (From: Todd Heberlein <email@hidden>)

  • Prev by Date: Re: NSString of selected text in NSTextView
  • Next by Date: Re: Embedded Frameworks in Plugin & Action Bundles
  • Previous by thread: Re: NSString of selected text in NSTextView
  • Next by thread: Best implementation for iTunes-like playlist structure?
  • Index(es):
    • Date
    • Thread