Search code examples
iphoneiosnsurl

Error with stringWithContentsOfURL encoding with à è ò ù character


I have a problem with this implementation:

NSString *s = [NSString stringWithContentsOfURL:[NSURL URLWithString:site] encoding:NSUTF8StringEncoding error:&er];

the string site contains this character with the accent, for example : à è ò ù and every time a string contains one of this character for example this string:

http://...../Questa_é_la_mia_terra.html 

the "s" string returns null, this happen also for other characters with the accent, how can I solve this problem?


Solution

  • i have found this solution:

    NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
    NULL,
    (CFStringRef)unencodedString,
    NULL,
    (CFStringRef)@"!*'();:@&=+$,/?%#[]",
    kCFStringEncodingUTF8 );
    

    and in this way seems work...from this website: http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/