Reputation: 456
I am getting html content as a string in my webservice response which contains " " in it. When I display that data in webview, " " is converted in junk character. Please let me know how to solve it.
Upvotes: 1
Views: 1028
Reputation: 155
stringByReplacingOccurrencesOfString is deprecated from ios 9
let decoded = yourString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
Upvotes: 0
Reputation: 19418
Use the stringByReplacingPercentEscapesUsingEncoding:
method of NSString
like :
NSString *decoded = [yourString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Also to remove
use
[yourString stringByReplacingOccurrencesOfString:@" " withString:@" "];
Upvotes: 0
Reputation: 15894
You have to read the string as NSUTF8 encoded string and then pass the string to web view using "loadHTML" method mentioned in UIWebView.
Not only that, if you want to display special characters like copy right, double quotes etc or other language characters in the HTML, you have to use UTF8 encoding.
Upvotes: 2