user2844801 user2844801 - 1 year ago 217
Objective-C Question

How do I remove/decode URL percent encoding?

I want to take a

and convert it to a more readable format. For example I have the following link:

I take away the unnecessary parts and am left with
as a
. Is there any sort of way to convert this into
"Sándor Font"
(what it actually should be), without having to type out every single combination of special characters and replacing each part of the string?

To demonstrate how I want to use this, I wrote the following sample code:

//request is a NSURLRequest with a url of

NSRange range = [[request.URL absoluteString] rangeOfString:@"/wiki/"];

NSString *substring = [[[request.URL absoluteString] substringFromIndex:NSMaxRange(range)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

//ArticleTitleLabel is a UILabel

self.ArticleTitleLabel.text = substring;

In the end I want the label to say
"Sándor Font"
. Thanks!

Answer Source

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding; on NSString is what you want.


[substring stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download