Magnus
Magnus

Reputation: 1442

Decoding HTML entities on iPhone

I have a list of several locations, some of them containing the letters æ, Æ, ø, Ø, å and Å. From the webservice I'm using, the letters comes out as "&oslash ;" "&Aring ;" etc.

When I download the feed from the webservice, I use UTF-8 encoding.

How can I decode the occurences of these characters?

Thanks!

Upvotes: 2

Views: 3210

Answers (3)

datwelk
datwelk

Reputation: 1037

A NSString category called "GTMNSString+HTML" written by Google works perfectly for me. Check it out here: https://gist.github.com/takuma104/ntlniph/blob/master/gtm/Foundation/GTMNSString+HTML.h & here: https://gist.github.com/takuma104/ntlniph/blob/master/gtm/Foundation/GTMNSString+HTML.m

Upvotes: 0

Stefan Ticu
Stefan Ticu

Reputation: 2103

There is no standard way, to make it simple write your own custom method (or NSString extension) and do this :

string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];

Upvotes: 1

Zoleas
Zoleas

Reputation: 4879

If your webservice is using utf8 and if you decode the data with [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], all should be ok.

Upvotes: 0

Related Questions