Skip to content

Instantly share code, notes, and snippets.

@fxbeckers
Created March 28, 2011 17:51
Show Gist options
  • Save fxbeckers/890923 to your computer and use it in GitHub Desktop.
Save fxbeckers/890923 to your computer and use it in GitHub Desktop.
Straightforward way of performing URL encoding and decoding of strings, especially useful for use in conjunction with TTNavigtor and URL Mapping
@interface NSString (FXNSStringAdditions)
- (NSString *)urlEncoded;
- (NSString *)urlDecoded;
@end
@implementation NSString (FXNSStringAdditions)
- (NSString *)urlEncoded {
NSString *result = (NSString *)
CFURLCreateStringByAddingPercentEscapes (kCFAllocatorDefault,(CFStringRef)self, NULL, CFSTR(":/?# []@!$&’()*+,;="), kCFStringEncodingASCII);
return [result autorelease];
}
- (NSString *)urlDecoded {
NSString *result = (NSString *)
CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)self,CFSTR(""), kCFStringEncodingASCII);
return [result autorelease];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment