How to decode a string in iphone

I want to decode my string. I used parsing and got the string from the RSS feed. On the line, these special characters are not allowed &, <,> in my application. On the server side, these characters are encoded and sent to the string. So now I got a string like

 Actual String : <Tom&Jerry>  (only these characters are not allowed in node data & < >).

 After Encoding:  %3CTom%26Jerry%3E.

But I need to display the line

                  <Tom&Jerry>

So how can I decode a string.

Please help me.

Thank.

+5
source share
3 answers

Use the method -stringByReplacingPercentEscapesUsingEncoding:.

[@"%3CTom%26Jerry%3E"
 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+12
source

Look for

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding 

Or an example:

NSString *input = @"Hello%20World";
NSString *output = [text stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@ becomes %@",input,output);

Log: Hello%20World becomes Hello World
+6
source

I got a response and my code,

     NSString *currentString =@"%3CTom%26Jerry%3E";

     NSString  * decodeString = [currentString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    lblTitle.text = decodeString;

Thank.

+4
source

All Articles