0

I have some text formatting issues that I need to solve. I have some strange characters displaying from the NSString below

the original string:

NSString *descriptionStringPreFormatted = [item objectForKey:@"title"];

the formatted string:

    NSString *descriptionLabelStringUTF8 = [descriptionStringPreFormatted stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"descriptionStringPreFormatted is %@", descriptionStringPreFormatted);
    NSLog(@"descriptionLabelStringUTF8 is %@", descriptionLabelStringUTF8);

here's the output which is the same whether I use the UTF8 encoding or not.

the output:

2013-01-05 16:44:51.807 descriptionStringPreFormatted is £144.99... 

2013-01-05 16:44:51.810 descriptionLabelStringUTF8 is £144.99...
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • 2
    what do you expect the string to be? Also I believe NSString will store string data as utf8 internally by default – Justin Meiners Jan 05 '13 at 16:56
  • some of the strings are displaying as: "£144.99..." instead of"£144.99..." note the "Â" infront of the £ symbol. The source I'm getting the string from displays as "£144.99..." so I'm not sure what's going on – hanumanDev Jan 05 '13 at 17:20
  • 1
    How are you creating the string? – Justin Meiners Jan 05 '13 at 17:21
  • I found the answer here: [stackoverflow link][1] [1]: http://stackoverflow.com/questions/4913499/utf8-character-decoding-in-objective-c – hanumanDev Jan 10 '13 at 16:44

1 Answers1

1

I think you are receiving dictionary "item" from web services. So try to decode that response string from webservice with NSUTF8StringEncoding. NSString *str=[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; here "responseData" is raw data coming from web services.

  • thanks for the response. What if I wanted to use stringWithContentsOfURL: instead of initWithData in that example? I'm currently getting the data via a URL in JSON format – hanumanDev Jan 06 '13 at 16:45