Reputation: 1135
I have a string that's encoded with JavaScript escape()
that i need to decode in objective-c, I've searched everywhere for a solution but I can't even find what type of encoding this is.
Sample string:
%3Cdiv%20id%3D%27wrapper%27%3E%3Cp%3EHello%20World%21%3C/p%3E%3C/div%3E
Upvotes: 0
Views: 368
Reputation: 23001
There is an NSString function you can use: stringByReplacingPercentEscapesUsingEncoding:
From the documentation:
Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.
Typically you should be using NSUTF8StringEncoding
for the encoding.
Example usage:
NSString *escaped = @"%3Cdiv%20id%3D%27wrapper%27%3E%3Cp%3EHello%20World%21%3C/p%3E%3C/div%3E";
NSString *unescaped = [escaped stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Upvotes: 1