• 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: Decoding html entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Decoding html entities


  • Subject: Re: Decoding html entities
  • From: Adam Leonard <email@hidden>
  • Date: Sun, 11 Jun 2006 21:07:47 -0700


On Jun 11, 2006, at 5:14 PM, Thom McGrath wrote:

Given that I only have 5 characters to decode, I wonder if it'd be better to use a find-replace instead. But it feels error-prone, and I see no method on the docs which can do a find-replace.


If you will really only encounter those 5 entities, find-replace probably would be the easiest (and fastest) NSMutableString has replaceOccurrencesOfString:withString:options:range:

So, use something like this (typed in Mail)

NSMutableArray *specialChars = [[NSMutableArray alloc]init];

[specialChars addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"quot",@"34",@"\"",nil] forKeys:[NSArray arrayWithObjects:@"orig",@"num",@"new",nil]]];

//(other entities)

//download the pages and do this for each page

NSEnumerator *enumeratorForSpecialChars= [specialChars objectEnumerator];
NSDictionary *dictionary;
while(dictionary = [enumeratorForSpecialChars nextObject])
{
[URLContentsAsMutableString replaceOccurrencesOfString:[NSString stringWithFormat:@"&%@;",[dictionary objectForKey:@"orig"]]
withString:[dict objectForKey:@"new"]
options:0
range:NSMakeRange(0,[URLContentsAsMutableString length])];

[URLContentsAsMutableString replaceOccurrencesOfString:[NSString stringWithFormat:@"&#%@;",[dict objectForKey:@"num"]]
withString:[dict objectForKey:@"new"]
options:0
range:NSMakeRange(0,[URLContentsAsMutableString length])];
}


[specialChars release];

_______________________________________________
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: 
 >Decoding html entities (From: Thom McGrath <email@hidden>)

  • Prev by Date: Re: Cocoa newb - Bus Error from TCP Server
  • Next by Date: Re: Decoding html entities
  • Previous by thread: Decoding html entities
  • Next by thread: Re: Decoding html entities
  • Index(es):
    • Date
    • Thread