Ethan Allen
Ethan Allen

Reputation: 14835

What's the opposite of stringByAddingPercentEscapesUsingEncoding:? What function takes out the % escapes?

What is the opposite of this:

modifiedTitle = [modifiedTitle stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

so that it makes a %20 appear as a space and a %26 appear as a &.

Upvotes: 2

Views: 1166

Answers (4)

MRizwan33
MRizwan33

Reputation: 2741

This is the alternative:

NSString *url = [modalData.imageURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

There are other character set too in docs.

Upvotes: 0

Dave DeLong
Dave DeLong

Reputation: 243156

Man... if only the two relevant methods were listed right next to each other in the documentation....

Oh wait.

Upvotes: 9

CodaFi
CodaFi

Reputation: 43330

All web-URL's are encoded some way some how. The most common of these is UTF-8. You can peruse the Encoding Standards, but know that %20 is a space and %26 is an ampersand in UTF-8, so use [myString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; to get rid of it.

Upvotes: 0

larsacus
larsacus

Reputation: 7346

The API you're looking for is stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding.

Upvotes: 5

Related Questions