开发者

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 s开发者_如何学JAVAtrText)
        {
            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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜