2

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!

Frederick Cheung
  • 79,397
  • 6
  • 137
  • 164
Magnus
  • 1,444
  • 5
  • 21
  • 30

3 Answers3

1

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

string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
Stefan Ticu
  • 2,063
  • 1
  • 12
  • 21
0

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

Zoleas
  • 4,759
  • 1
  • 18
  • 31
  • 1
    According to his question, his web service is sending html-encoded text. The fact that the stream is UTF-8 is irrelevant. If he creates the string as described here, the `ø` is not going to turn into Ø, it's just going to be the 8 character, UTF-8 encoded string `ø` – Jason Coco Jan 04 '12 at 09:02
  • My bad, it's actually the html-encoded wich is the problem, I agree with you. – Zoleas Jan 04 '12 at 09:16
0

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

datwelk
  • 962
  • 1
  • 8
  • 20