URL encoding

23 02 2008

I look for Cocoa methods those can perform “URL encode”, just like uri_escape in perl. NSString’s stringByAddingPercentEscapesUsingEncoding: works for some characters, but does not encode characters like ‘=’(equal) and ‘ ‘(white space).

However, CoreFoundation function CFURLCreateStringByAddingPercentEscapes does what I want.

CFStringRef param1_encoded = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)param1, NULL, (CFStringRef)@";/?:@&=+$,", kCFStringEncodingUTF8);

It seems that this fact is rediscovered by many Cocoa developers…


Actions

Information

Leave a comment