I am getting character codes (' and &quote;) that are breaking my responses (showing 39; and uto;) when returning a string from an HttpWebRequest:
internal static void TranslateThis(Player player, string fromLang, string toLang, string text){
try
{
string translated = null;
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("http://translate.google.com/?langpair=" + fromLang + "|" + toLang + "&text=" + text.Replace(" ", "+") + "#");
HttpWebResponse res = (HttpWebResponse)hwr.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string html = sr.ReadToEnd();
int a = html.IndexOf("onmouseout=\"this.style.backgroundColor='#fff'\">") + 47;
int b = html.IndexOf("</span>",html.IndexOf("onmouseout=\"this.style.backgroundColor='#fff'\">") + 47);
translated = html.Substring(a, b - a);
if (translated.Length < (10 * text.Length)){
if (player == Player.Console)
{
player.ParseMessage(translated, true);
}
else
{
player.ParseMessage(translated, false);
}
} else {
player.Message("Usage: /translate [lang] [message]");
}
}
catch
{
player.Message("Usage: /translate [lang] [message]");
}
}