using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
public class translate
{
public translate()
{
}
public string translates(string translatestr)
{
string googletranslateurl = "http://translate.google.com/translate_t?langpair=zh|en&hl=en&ie=utf-8&text=" + translatestr;
string translatestext = SniffwebCode(gethtmlsource(googletranslateurl), "<div id=result_box dir=\"ltr\">", "</div>");
return translatestext;
}
public string gethtmlsource(string url)
{
string charset = "utf-8";
string htmlsource = "";
try
{
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.GetEncoding(charset));
htmlsource = reader1.ReadToEnd();
stream1.Close();
response1.Close();
}
catch
{
}
return htmlsource;
}
public string SniffwebCode(string code, string wordsBegin, string wordsEnd)
{
string NewsTitle = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
&nbs |