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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With