因为时间太紧,无意冒范论坛规则,请大家原谅;
在DELPHI里,如何用google在线翻译页面里:http://translate.google.cn/translate_t?hl=zh-CN#把要翻译的内容提交上去,然后得到它翻译回来的中文;
希望大家能伸出温暖的十指,200元不多,当是和大家学习学习,谢谢
在DELPHI里,如何用google在线翻译页面里:http://translate.google.cn/translate_t?hl=zh-CN#把要翻译的内容提交上去,然后得到它翻译回来的中文;
希望大家能伸出温暖的十指,200元不多,当是和大家学习学习,谢谢
function URLEncode(const S: string; const InQueryString: Boolean): string;
var
Idx: Integer; // loops thru characters in string
begin
Result := '';
for Idx := 1 to Length(S) do
begin
case S[Idx] of
'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
Result := Result + S[Idx];
' ':
if InQueryString then
Result := Result + '+'
else
Result := Result + '%20';
else
Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2);
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
word: string;
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
word := Memo2.Text;
IdHttp1.Get('http://translate.google.cn/translate_a/t?client=t&text=' + UrlEncode(Word, False) +'&sl=en&tl=zh-CN', ms);
ms.Position := 0;
Memo1.Lines.LoadFromStream(ms);
ms.Free;
end;
现在是如果翻译的字符超过一定数的时候会有抛出异常,你的方法比较简洁,能否再优化一下解决.
IdHttp1.Get('http://translate.google.cn/translate_a/t?client=t&text=' + UrlEncode(Word, False) +'&sl=en&tl=zh-CN', ms);换成POST后,都没有数据回来了.
http://translate.google.cn/translate_t?hl=zh-CN#能帮我看看吗,可能给个例子.