如何在C#Winform应用程序中使用UTF-16编码

时间:2018-08-14 00:49:15

标签: c# winforms encoding google-translate utf

我正在尝试使用Google翻译进行某些句子翻译(英语到乌尔都语也不能使用阿拉伯语),但是我遇到了问题。

当我单击按钮时,它会返回一些符号。  我用这个答案链接 getting the translated language using google translator in winform apps

但是它没有按照我的要求工作。我认为问题在于UTF编码。 不支持UTF16。我使用了Unicode,但也无法正常工作。 我还在PC中安装了所需的语言。

感谢您的帮助。 谢谢。

            string input = "How are you";
            string languagePair = "en|ur";

            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>"));
            result = HttpUtility.HtmlDecode(result.Trim());

            MessageBox.Show(result);

0 个答案:

没有答案