1

i have a uiwebview. when i read string (from ) from this uiwebview i encodes come characters like #. how can i decode?

for example it gives %23test instead of #test. i need #test

thanks.

ysnky
  • 281
  • 4
  • 12

1 Answers1

2

You can use the stringByReplacingPercentEscapesUsingEncoding: method of NSString:

NSString *encoded = @"%23test";
NSString *decoded = [encoded stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  • hi aBitObvious, it has problems while getting % char. it gives "%58'den ysnky'ye tepki" as "X'den ysnky'ye tepki". how can i solve? thanks. http://stackoverflow.com/questions/4338123/decoding-problem-uiwebview – ysnky Dec 02 '10 at 18:00
  • What string are you expecting back? –  Dec 02 '10 at 18:21
  • my string is "%58'den ysnky'ye tepki". i would like to write is as and when clicked i want to get it back. – ysnky Dec 03 '10 at 06:30
  • Before putting the string into the html, encode it using `stringByAddingPercentEscapesUsingEncoding`. For the `href`, use double quotes instead of single quote to delimit the url: `NSString *html = [NSString stringWithFormat:@"Click This", encodedString];`. –  Dec 03 '10 at 17:01
  • oohh, right. i was missing that single quote deliminating the string. thanks again. – ysnky Dec 04 '10 at 20:37