Piero
Piero

Reputation: 9273

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?

Upvotes: 0

Views: 262

Answers (2)

Piero
Piero

Reputation: 9273

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/

Upvotes: 1

Merott
Merott

Reputation: 7379

Encode site using stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding first.

See Working with URLs

Upvotes: 0

Related Questions