Hi ,
How to do URL encoding in NSURL ?
Thanks
You can use stringByAddingPercentEscapesUsingEncoding:
NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
However, in my experience, this method isn't quite perfect (in handling some reserved characters), and in many cases I needed to use the variant:
NSString * escapedUrlString =
(NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unescapedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );
stringByAddingPercentEscapesUsingEncoding: has some problems with URL arguments.
In conjunction I use gtm_stringByEscapingForURLArgument from Google Toolbox for Mac for URL arguments.