WP7 WebControl字符编码

时间:2012-06-14 11:42:40

标签: html windows-phone-7 dynamic-web-controls

我有一小段HTML

<b>OBNUBIL�,</b> 
<abbr class="abbrev" title="persoană">pers.</abbr>
 3 <i>obnubilează,</i> 
<abbr class="abbrev" title="verb">vb.</abbr>
 I. <abbr class="abbrev" title="reflexiv">Refl.</abbr> 
(Rar; despre vedere, memorie) A se �ntuneca, a slăbi, a se umbri.  Din 
<abbr class="abbrev" title="limba latină">lat.</abbr> 
<b>obnubilare,</b> 
<abbr class="abbrev" title="limba franceză">fr.</abbr> 
<b>obnubiler.</b>

我希望在用C#编写的Windows Phone应用程序上的WebBrowser中显示。这段HTML存储在一个字符串中:str2. 我使用了这行代码:webBrowser1.NavigateToString(str2)。 它有效但Romanian diacritics (ă ,ș ,ț,�, � ,Ă,Ț ,�,�,Ș)未显示 如何在Windows Phone中将WebControl的字符编码从UTF-8更改为ISO-8859-16?

    private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // Showing the exact error message is useful for debugging. In a finalized application, 
                // output a friendly and applicable string to the user instead. 
                MessageBox.Show(e.Error.Message);
            });
        }
        else
        {
            string textString = (string)e.Result;
            string fixedString = "";


            // This search returns the substring between two strings, so 
            // the first index is moved to the character just after the first string.
            string defStart = "cuvânt\">";
            string defEnds = "</span>  <br/>";
            textString = textString.Replace("\r", "").Replace("\n", "");
            int first = textString.IndexOf(defStart) + defStart.Length;
            int last = textString.LastIndexOf(defEnds);
            string str2 =textString.Substring(first, last - first);
            str2 = str2.Replace("&#x2013;", " - ");

            // Remove tab spaces
            str2 = str2.Replace("\t", " ");
            // Remove multiple white spaces from HTML
            str2 = Regex.Replace(str2, "\\s+", " ");

            //str2 = Regex.Replace(str2, "<[^>]+>", string.Empty);
            //BannerTextBlock.Text=str2;

            webBrowser1.NavigateToString(str2);



        }
    }

我希望有人能理解我的问题并帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:0)

我只是帮助你了解网络环境中的知识:

如果你显示这种类型的字符:“Ô,“Ô,“Ô,...... =&GT;数据以UTF-8保存,浏览器认为他必须处理 ISO

如果你显示这种类型的char:“ ” =&GT;数据保存在ISO 中,浏览器认为他必须处理 UTF-8

PS:对不起我的英语。

希望我帮助你。