Cfaniak
Cfaniak

Reputation: 409

silverlight/wpf webbrowser encoding

i was looking for a long time to get a solution for polish charset in wpf webbrowser. After few hours of playing i made a solution, maybe someone else will need it also so i share.

private string EncodeUnicode(string strText)
    {
        string txtUnicode = "";
        foreach (char value in strText)
        {
            txtUnicode += Regex.Replace(Convert.ToString(value), "[ęóąśłżźćńĘÓĄŚŁŻŹŃ]", "&#" + (int.Parse(string.Format("{0:x4}", (int)value), System.Globalization.NumberStyles.HexNumber)).ToString());
        }
        return txtUnicode;
    }

Ofcourse you can replace ęóąśłżźćńĘÓĄŚŁŻŹŃ with your pattern. And than just use

WebBrowser.NavigateToString(EncodeUnicode(Content));

If someone got better solution plz share it also.

Upvotes: 2

Views: 1627

Answers (1)

Łukasz Wiatrak
Łukasz Wiatrak

Reputation: 2767

Try to add

<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>

within <head></head> tag of your html string.

I had the same problem, your solution worked for me, and this worked too.

Upvotes: 1

Related Questions