<form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form>
<pre>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { TranslateText(TextBox1.Text, "en|ar");//Hindi to English } public string TranslateText(string input, string languagePair) { string url = String.Format("http://www.google.com/translate_t?hl=ar&en=UTF8&text={0}&langpair={1}", input, languagePair); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; string result = webClient.DownloadString(url); int index1 = Convert.ToInt32(result.IndexOf("onmouseout=" + '"' + "this." + "style." + "backgroundColor" + "=" + "'" + "#fff" + "'" + '"' + ">"));//onmouseout="this.style.backgroundColor='#fff'"> int index2 = Convert.ToInt32(result.IndexOf("id=" + '"' + "gt-edit" + '"')); int index3 = index2 - index1; result = result.Substring((index1 + 47), (index3 - 49)); Label1.Text = result.ToString(); return result; } }
Thank u...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)