Last active
March 2, 2016 17:21
-
-
Save rsimenok/137d9465a96142dd8d8f to your computer and use it in GitHub Desktop.
Methods to encode and decode URLs to replace "/" and "&".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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