Dhaval Rathod
Dhaval Rathod

Reputation: 456

Junk character in Webview

I am getting html content as a string in my webservice response which contains "&nbsp" in it. When I display that data in webview, "&nbsp" is converted in junk character. Please let me know how to solve it.

Upvotes: 1

Views: 1028

Answers (3)

Bhavesh Tiwari
Bhavesh Tiwari

Reputation: 155

stringByReplacingOccurrencesOfString is deprecated from ios 9

let decoded = yourString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())

Upvotes: 0

Maulik
Maulik

Reputation: 19418

Use the stringByReplacingPercentEscapesUsingEncoding: method of NSString

like :

NSString *decoded = [yourString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Also to remove   use

[yourString stringByReplacingOccurrencesOfString:@" " withString:@" "];

Upvotes: 0

Satyam
Satyam

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

Related Questions