Search code examples
iosencodingnsstringwindows-1252

Replacing some characters in a NSString


I have this XML file encoded in windows-1252 and I haven't found any method to get a proper UTF-8 encoding from this file so far. It's a file containing a lot of accented characters that I need to display.

What I want to do, is to replace any encoding windows-1252 character myself. I would like to know how to do this :

NSString * eat = @"j'ai mangU00c8 une pomme";

to

NSString neweat = @"j'ai mangé une pomme";

I found many ways to replace a character which is not in a word, but I need here to replace characters (so here U00c8) that can be anywhere in a given string.


Solution

  • DEcoding is not giving you proper result try this

       NSString * eat = @"j'ai mangU00c8 une pomme";
    
        eat = [eat stringByReplacingOccurrencesOfString:@"U00c8"
                                             withString:@"é"];