• 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: range from link
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: range from link


  • Subject: Re: range from link
  • From: Philip Dow <email@hidden>
  • Date: Tue, 2 Aug 2005 18:09:56 +0200

Robert, you have to parse the attributed strange querying for the effective range, a la:

for ( i = 0; i < [attributedString length]; i++ ) {

//check for a link
if ( [attributedString attribute:NSLinkAttributeName atIndex:i effectiveRange:&effectiveRange] ) {


//grab the link text
NSString *linkSub = [[attributedString string] substringWithRange:effectiveRange];
NSString *linkString;


//grab the url from this guy and use it if it exists
NSURL *linkURL = [attributedString attribute:NSLinkAttributeName atIndex:i effectiveRange:nil];


if ( linkURL ) {
linkString = [NSString stringWithFormat:@"<a href='% @'>%@</a>", [linkURL absoluteString],
(NSString*) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (CFStringRef)linkSub,CFSTR(""),kCFStringEncodingUTF8)];
}
else {
linkString = [NSString stringWithFormat:@"<a href='% @'>%@</a>", linkSub,
(NSString*) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (CFStringRef)linkSub,CFSTR(""),kCFStringEncodingUTF8)];
}


 }

That bit of code there will find a link and build html out of it. You can find more info somewhere in attributed string's documentation on parsing for font information.

-Phil
http://phildow.net

Am 02.08.2005 um 17:56 schrieb Robert Miller:

Hello,

Here's a basic question that I've not been able to find an answer for, I hope someone can help. Is there a way to determine the range in an attributed string for a given link id value. I'm using the API:

[myAttributedString addAttribute:NSLinkAttributeName value:myID range:range];

but it seems there is no API to retrieve the range of text once the link attribute is set for the id value. Is there something like - (NSRange) rangeForLinkValue:(id)value available anywhere ?

Thanks in advance for any help.
Regards,
Bob M.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >range from link (From: Robert Miller <email@hidden>)

  • Prev by Date: Re: NSStatusBar generates Sigtrap
  • Next by Date: Re: NSOutlineView and NSTreeController
  • Previous by thread: range from link
  • Next by thread: App crash after javascript called window closes
  • Index(es):
    • Date
    • Thread