Click here to Skip to main content
14,087,117 members
Rate this:
Please Sign up or sign in to vote.
hello, the following code is to convert from English to Arabic but somehow the Arabic appear as a question mark, but when converting from arbic to English it's work I don't if some one can help me, I will be appreciate

this is for design code

<form id="form1" runat="server">
        <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>

and this is for code behind

What I have tried:

<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("{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="'#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...
Mehdi Gholam 22-Jul-17 6:31am
? in your output is a presentation problem to do with character encoding in you html or font settings.
Graeme_Grant 22-Jul-17 7:02am
Does it work as expected if you do it manually with Google Translate?

Side Note: If Google become aware of what you are doing, and they will, you will find that your website will stop working. The correct way is to use their Google Cloud Translation API[^]
Learn.net37 23-Jul-17 4:16am
thank u but this for testing and I already solve this by change web client.Encoding = System.Text.Encoding.UTF8; to webClient.Encoding = System.Text.Encoding.GetEncoding("windows-1256");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 22 Jul 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100