zoukankan      html  css  js  c++  java
  • Windows Phone 7 WebBrowser 中文乱码问题

    通过WebBrowser直接请求网页,是正常显示的,只是通过获取到字符串,再通过NavigateToString()就会显示乱码.

    中文转换成 Unicode编码就可以了 :

        public static string Unicode2HTML(string HTML)

        {

                StringBuilder str = new StringBuilder();

                char c;

                for (int i = 0; i < HTML.Length; i++)

                {

                    c = HTML[i];

                    if (Convert.ToInt32(c) > 127)

                    {

                        str.Append("&#" + Convert.ToInt32(c) + ";");

                    }

                    else

                    {

                        str.Append(c);

                    }

                }

                return str.ToString();

           }

           private void RenderPage()

            {

                var html = FxConstants.ArticleViewTemplate

                    .Replace("{article-header}", _SelectedRssItem.Title)

                    .Replace("{article-content}", _Content)

                    .Replace("{background-specific-style}",

                             PhoneUI.CurrentPhoneBackground == PhoneBackground.Dark

                                 ? Fx.Instance.Settings["Article-View-DarkBackground-CSS"]

                                 : Fx.Instance.Settings["Article-View-LightBackground-CSS"])

                    .Replace("{common-style}", Fx.Instance.Settings["Article-View-CSS"]);

                html = Unicode2HTML(html);

                Browser.NavigateToString(html);

            }

    欢迎大家扫描下面二维码成为我的客户,为你服务和上云

  • 相关阅读:
    Linux基础命令(一)
    You've made choice
    protege推理
    字符编码
    第二次作业
    数据类型-集合set
    数据类型-元组&字典
    数据类型-列表
    数据类型-数值&字符串
    流程控制之for循环
  • 原文地址:https://www.cnblogs.com/shanyou/p/2284208.html
Copyright © 2011-2022 走看看