Just create an interface by following this code.

@interface MREntitiesConverter : NSObject {
NSMutableString* resultString;
}
@property (nonatomic, retain) NSMutableString* resultString;
- (NSString*)convertEntiesInString:(NSString*)s;
@end

@implementation MREntitiesConverter
@synthesize resultString;
- (id)init
{
if([super init]) {
//resultString = [[NSMutableString alloc] init];
}
return self;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)s {
[self.resultString appendString:s];
}
- (NSString*)convertEntiesInString:(NSString*)s {
if(s == nil) {
NSLog(@”ERROR : Parameter string is nil”);
}
resultString = [[NSMutableString alloc] init];
NSString* xmlStr = [NSString stringWithFormat:@"%@", s];
NSData *data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSXMLParser* xmlParse = [[NSXMLParser alloc] initWithData:data];
[xmlParse setDelegate:self];
[xmlParse parse];
NSString* returnStr = [[NSString alloc] initWithFormat:@”%@”,resultString];
[resultString release];
return returnStr;
}
- (void)dealloc {
//[resultString release];
[super dealloc];
}
@end

When you want to decode HTML characters within a string, just call the app like this.

MREntitiesConverter *converter = [[MREntitiesConverter alloc] init];
someStr = [converter convertEntiesInString:@"abcdefghiijXXXYZ"];
[converter release];

Easy enough? ;)


Tagged with:
 

Facebook comments:

2 Responses to Decode HTML characters in iPhone SDK with Objective-C

  1. Magnificent items from you, man.I have read your blog and i got a very useful and knowledgeable information from your blog.its really a very nice article.
    I really like what you’ve acquired here, certainly like what you’re saying and the way in which by which you assert it. You’re
    making it entertaining and you continue to care for to stay it sensible.

  2. Hello there I am so delighted I found your blog page, I really found you by mistake, while I was researching for something else,
    Regardless I am here now and would just like to say many thanks for a remarkable post and a all round enjoyable blog.Please do keep up the excellent work.
    industrial training indore

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

reverse phone lookupTattoo DesignsSEO