Re: NSString of selected text in NSTextView
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