H.Al H.Al - 5 months ago 20
Vb.net Question

How to use google translate in vb.net

I am working on a small function that translates string to different languages. Actually it's working fine for all languages except Arabic, it's returning question marks ???? . Any hint? You can view the code below
Thanks in advance

Dim translateThis = "hello"
Dim languagePair = "en|ar"
Dim url3 = String.Format("http://www.google.com/translate_t?hl=en&text={0}&langpair={1}", translateThis, languagePair)
Dim result as string

Dim client As WebClient = New WebClient()
client.Encoding = System.Text.UTF8Encoding.UTF8

result = client.DownloadString(url3)
result = result.Substring(result.IndexOf("id=result_box") + 151, 500)
result = result.Substring(0, result.IndexOf("</span>"))

Answer

Try to use for Arabic Windows Encoding(1256) :

client.Encoding = Encoding.GetEncoding(1256)