H.Al H.Al - 1 year ago 70
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>"))


Try to use for Arabic Windows Encoding(1256) :

client.Encoding = Encoding.GetEncoding(1256)