Skip to content

Instantly share code, notes, and snippets.

@rsimenok
Last active March 2, 2016 17:21
Show Gist options
  • Save rsimenok/137d9465a96142dd8d8f to your computer and use it in GitHub Desktop.
Save rsimenok/137d9465a96142dd8d8f to your computer and use it in GitHub Desktop.
Methods to encode and decode URLs to replace "/" and "&".
// Encode a string to embed in an URL.
+(NSString *)encodeString:(NSString *)string {
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(nil, (CFStringRef)string, nil, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8));
}
// Decode a percent escape encoded string.
+(NSString *)decodeString:(NSString *)string {
return CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(nil, (CFStringRef)string, CFSTR(""), kCFStringEncodingUTF8));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment