How-To: URL Encode NSString in Objective-C
Jan.21, 2009 in
Tech
It’s very easy to URL Encode an NSString in Objective-C (i.e. make a string safe to send using a GET request). Simply do this:
NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
Then just use the escapedUrlString in your NSURL object and you’re on your way.

February 10th, 2009 at 8:34 pm
How-To: URL Encode NSString in Objective-C…
You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…
August 4th, 2009 at 2:36 pm
nice easy fix, thanks
August 27th, 2009 at 10:58 pm
If you’re a developer which lives outside the US, you have to deal most of the time with foreign characters etc. NSUTF8StringEncoding does the trick.
November 16th, 2009 at 5:09 am
This actually doesn’t work. I tried it on a string containing a plus sign (+), and it did not convert it to %2B. Took me a while, but once I caught this, my application worked as expected. I’m looking for some other built in URL encoding, but in the mean time this table seems to be correct as to what needs to be replaced:
http://webdesign.about.com/od/forms/a/url_encoding.htm
February 19th, 2010 at 3:37 pm
NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)yourtext,NULL,(CFStringRef)@”!*’();:@&=+$,/?%#[]“,kCFStringEncodingUTF8 );