URL Encoding an NSString

February 26, 2013 in iOS Snippets


+ (NSString*)urlEncodeString:(NSString*)str;

{

return (__bridge_transfer NSString *)

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

}