在 Delphi 中使用微软全文翻译的小例子
来源:互联网 发布:淘宝卖的火柴枪合法么 编辑:程序博客网 时间:2024/04/28 00:33
刚刚从博客园看到有朋友用 C# 做了这么个东西, 我用 Delphi 尝试了一下.
需要先去申请一个 AppID: http://www.bing.com/toolbox/bingdeveloper/
使用帮助在: http://msdn.microsoft.com/en-us/library/dd576287.aspx
效果图:
使用 Indy:
需要先去申请一个 AppID: http://www.bing.com/toolbox/bingdeveloper/
使用帮助在: http://msdn.microsoft.com/en-us/library/dd576287.aspx
uses MsXML;{函数}function Translate(AAppID: string; AText: string; InLanguage: string='en'; OutLanguage: string='zh-CHS'): string;const BaseUrl = 'http://api.microsofttranslator.com/V2/http.svc/Translate?appId=%s&text=%s&from=%s&to=%s';var Url: string; req: IXMLHTTPRequest;begin Url := Format(BaseUrl, [AAppID, AText, InLanguage, OutLanguage]); req := CoXMLHTTP.Create; req.open('Get', Url, False, EmptyParam, EmptyParam); req.send(EmptyParam); Result := req.responseText; Result := Copy(Result, 68+1, Length(Result)-68-9); //去掉前后的标签end;{调用测试}procedure TForm1.Button1Click(Sender: TObject);const myAppId = '65FCA293BDB85C98D16A567C3FECE22272B6****'; //这是我申请的 AppID, 隐藏了后四位begin Memo2.Text := Translate(myAppId, Memo1.Text);end;
效果图:
使用 Indy:
uses IdHTTP;function Translate2(AAppID: string; AText: string; InLanguage: string='en'; OutLanguage: string='zh-CHS'): string;const BaseUrl = 'http://api.microsofttranslator.com/V2/http.svc/Translate?appId=%s&text=%s&from=%s&to=%s';var Url: string; stream: TStringStream; idHttpObj: TIdHTTP;begin stream := TStringStream.Create; idHttpObj := TIdHTTP.Create(nil); Url := Format(BaseUrl, [AAppID, Trim(AText), InLanguage, OutLanguage]); idHttpObj.Get(Url, stream); Result := stream.DataString; Result := Copy(Result, 68+1, Length(Result)-68-9); //去掉前后的标签 idHttpObj.Free; stream.Free;end;
- 在 Delphi 中使用微软全文翻译的小例子
- 在全文索引中同义词的使用
- 在全文索引中同义词的使用
- 在全文索引中同义词的使用
- Delphi 中WIN32系统注册表的读写方法小例子
- PHPRPC for delphi 在Form中使用例子
- .net 中MSMQ的使用--小例子
- 在自己的Portlet中使用Liferay的全文检索
- delphi中使用adoconnection 的openschema的例子源代码
- Delphi XE7中蓝牙 Bluetooth例子的使用
- lucene全文检索小例子
- 在Delphi中使用复杂的SQL
- 在Delphi中WaitForMultipleObjects的使用
- 在asp.net 2.0中使用存储过程的小例子
- 基于全文检索引擎Lucene的一个小例子
- 微软使用的术语翻译表
- 微软Bing翻译API的使用
- 在Sql Server中使用全文检索
- 总结Objective-C特点
- Asp.net验证码-转载
- 此刻的心情
- C#判断某元素是否存在数组中
- 第一篇博客
- 在 Delphi 中使用微软全文翻译的小例子
- 孤儿进程与僵尸进程【一】
- CPU 和 内存 关系 详解
- SQLite入门与分析(四)---Page Cache之事务处理(1)
- ASP.NET验证码-2
- 兴趣班哈。
- php+apache+mysql环境配置。。。
- HTML/JavaScript - Select list - Add/Remove Options (DOM)
- 事件代码: 4009 事件消息: 视图状态验证失败。 原因: 提供的视图状态未通过完整性检查。