M
mystudy
Unregistered / Unconfirmed
GUEST, unregistred user!
我用IdHTTP得GOOGLE网页的翻译内容,但是当是日文和韩文的时候会是乱码,不知道为什么,代码如下:
function TForm1.TransEngToOther(str: string; Index: integer): string;
var
i,Inicial,Final:integer;
s, s1: TStringStream;
ss:widestring;
begin
ss:='';
result:='';
i:= Index;
try
s := TStringStream.Create('');
s1 := TStringStream.Create('');
//s.WriteString('langpair='+TransStr[i,1]+'&hl=en&ie=Utf-8&text='+(memo1.Text));
s.WriteString('langpair='+TransStr[i,1]+'&hl=ja&ie=utf-8&text='+(str));
http.Request.ContentType := 'application/x-www-form-urlencoded';
try
http.Post('http://translate.google.com/translate_t', s, s1);
// http.Get('http://translate.google.com/translate_t?langpair='+TransStr[i,1]+'&hl=en&ie=UTF-8&text='+str, s1);
except
http.Get(http.Response.Location, s1);
end;
Inicial := Pos('<textarea',s1.DataString); //获得文本框开头文本
Final := Pos('</textarea>',s1.DataString); //获得文本框结尾
ss := Copy(s1.DataString,Inicial,Final-Inicial);
Inicial:=pos('>',ss)+1;
ss:=copy(ss,Inicial,length(ss)-Inicial+1);
result := ss;
finally
s.Free;
s1.Free;
end;
end;
在线等
function TForm1.TransEngToOther(str: string; Index: integer): string;
var
i,Inicial,Final:integer;
s, s1: TStringStream;
ss:widestring;
begin
ss:='';
result:='';
i:= Index;
try
s := TStringStream.Create('');
s1 := TStringStream.Create('');
//s.WriteString('langpair='+TransStr[i,1]+'&hl=en&ie=Utf-8&text='+(memo1.Text));
s.WriteString('langpair='+TransStr[i,1]+'&hl=ja&ie=utf-8&text='+(str));
http.Request.ContentType := 'application/x-www-form-urlencoded';
try
http.Post('http://translate.google.com/translate_t', s, s1);
// http.Get('http://translate.google.com/translate_t?langpair='+TransStr[i,1]+'&hl=en&ie=UTF-8&text='+str, s1);
except
http.Get(http.Response.Location, s1);
end;
Inicial := Pos('<textarea',s1.DataString); //获得文本框开头文本
Final := Pos('</textarea>',s1.DataString); //获得文本框结尾
ss := Copy(s1.DataString,Inicial,Final-Inicial);
Inicial:=pos('>',ss)+1;
ss:=copy(ss,Inicial,length(ss)-Inicial+1);
result := ss;
finally
s.Free;
s1.Free;
end;
end;
在线等