How to decode URL string on an iOS
Often times we need to deal with URL encoded string. This is quite awkward to use for an UI. In order to fix this issue, we often tend to decode it.
Today we will see how to decode an URL string on an iOS
Say, NSString* inputURLString
is an URL string you want to decode. It can be achieved as follows
For convenience purpose, I have made a category
NSString+DecodeString
onNSString
- (NSString*)decodeString {
return (__bridge NSString *) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef) self, CFSTR(""), kCFStringEncodingUTF8);
}
As simple as it could get. You can replace self
with NSString
parameter if you want to pass it as a method parameter instead of creating a category.