• 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 and decoding HTML Entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString and decoding HTML Entities


  • Subject: Re: NSString and decoding HTML Entities
  • From: Stuart Malin <email@hidden>
  • Date: Sun, 5 Apr 2009 11:52:24 -1000


On Apr 5, 2009, at 11:32 AM, I. Savant wrote:

On Apr 5, 2009, at 4:35 PM, Stuart Malin wrote:

The source is not HTML tagged, but contains HTML entities.

see:
http://www.w3schools.com/tags/ref_entities.asp
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references


So, for instance, I want to convert "--&gt;" to "-->"

No need for an attributed string.

Thanks, but I understand the difference perfectly, but it's irrelevant. HTML entities are HTML too, so this worked fine:


NSMutableAttributedString * aStr = [[NSMutableAttributedString alloc] initWithHTML:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"file:///Users/me/test.html"]] documentAttributes:nil];
[textView replaceCharactersInRange:NSMakeRange(0, [[textView string] length]) withString:[aStr string]];


... with an HTML file containing the entity &gt (NSData from local file for convenient illustrative purposes) but your method is probably more direct / efficient. I referenced the above because you said, "I can't seem to find an NSString method to do so (not that I sometimes don't easily miss the obvious)."

It's not strictly NSString, but might have worked fine for you.

Sorry, I.S., I didn't mean to imply that you didn't understand the difference -- just wanted to be clear for others following this thread as the distinction between percent escaping and entity decoding is often confused.


Your point that HTML entities are HTML is sensible, and more important, valid. Thank you for taking the time to build a test case.

The approach you have taken certainly offers much greater functionality, so I appreciate your posting this -- I may end up using it as well.


_______________________________________________

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


  • Follow-Ups:
    • Re: NSString and decoding HTML Entities
      • From: "I. Savant" <email@hidden>
References: 
 >NSString and decoding HTML Entities (From: Stuart Malin <email@hidden>)
 >Re: NSString and decoding HTML Entities (From: "I. Savant" <email@hidden>)
 >Re: NSString and decoding HTML Entities (From: Stuart Malin <email@hidden>)
 >Re: NSString and decoding HTML Entities (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: creating related objects
  • Next by Date: Re: Beachball on Lengthy Task
  • Previous by thread: Re: NSString and decoding HTML Entities
  • Next by thread: Re: NSString and decoding HTML Entities
  • Index(es):
    • Date
    • Thread