带有特殊字符的C#WindowsApp TextBox

时间:2010-03-11 09:30:40

标签: c# textbox richtextbox special-characters

我想要包含一个textbox / richtextbox,我希望在其中包含

等文本
"jogħġbok żomm din il-bieb magħluq". 

当我将此文本放在textbox / rightext框中时,我得到以下内容:

jogħġbok żomm din il-bieb magħluq

你能帮忙吗?

我从谷歌翻译获得字符串:

        string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", 
            input, languagePair);
        WebClient webClient = new WebClient();
        webClient.Encoding = System.Text.Encoding.UTF8;
        string result = webClient.DownloadString(url);
        result = result.Substring(result.IndexOf("<span title=\"") + "<span title=\"".Length);
        result = result.Substring(result.IndexOf(">") + 1);
        result = result.Substring(0, result.IndexOf("</span>"));
        return result.Trim();

修改

我想转换:

"jog&#295;&#289;bok &#380;omm din il-bieb mag&#295;luq"

"jogħġbok żomm din il-bieb magħluq"

1 个答案:

答案 0 :(得分:3)

你可以使用System.Web.HttpUtility.HtmlDecode转换html文本:

        string str = "jog&#295;&#289;bok &#380;omm din il-bieb mag&#295;luq";
        str = System.Web.HttpUtility.HtmlDecode(str); 
        textBox1.Text = str;
        richTextBox1.Text = str;