Re: Decoding html entities
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