Created
January 2, 2013 20:08
-
-
Save codeswimmer/4437501 to your computer and use it in GitHub Desktop.
iOS: URL Encode A String
This file contains hidden or 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
| This is useful so that before you process any URL request from a URL String, this URL String becomeURL encoded and gets replaced to percent escapes. | |
| iOS 5: iOS 5 requires A Toll-Free Bridging | |
| - (NSString *)escape:(NSString *)text | |
| { | |
| return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)text, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); | |
| } | |
| Previous iOS: | |
| - (NSString *)escape:(NSString *)text | |
| { | |
| return (NSString *)CFURLCreateStringByAddingPercentEscapes( | |
| NULL, | |
| (CFStringRef)text, | |
| NULL, | |
| (CFStringRef)@"!*'();:@&=+$,/?%#[]", | |
| CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment