我正在尝试使用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);