如何在 2009 年之前的 Delphi 中解码包含日语字符的 url?
我需要解码:
file://localhost/G:/test/%E6%B0%97%E3%81%BE%E3%81%90%E3%82%8C%E3%83%AD%E3%83%9E%E3%83%B3%E3%83%86%E3%82%A3%E3%83%83%E3%82%AF.mp3
进入
file://localhost/G:/test/気まぐれロマンティック.mp3
How to do it in Delphi before 2009(我使用Delphi 2006)?
I need to decode:
file://localhost/G:/test/%E6%B0%97%E3%81%BE%E3%81%90%E3%82%8C%E3%83%AD%E3%83%9E%E3%83%B3%E3%83%86%E3%82%A3%E3%83%83%E3%82%AF.mp3
into
file://localhost/G:/test/気まぐれロマンティック.mp3
How to do it in Delphi prior 2009 (I use Delphi 2006) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有Delphi 2006,所以我在Delphi 2007上测试了代码;你应该:
将带有“%”字符的字符串转换为纯UTF8字符串;
将 UTF8 字符串转换为宽字符串 (UTF8Decode);
使用日语编码将宽字符串转换为 Ansi 字符串(WideCharToMultiByte):
当我使用不同字体测试上述代码时,与问题中的日语字符串相比,名称以“@”开头的字体中的日语符号出现逆时针旋转 90 度。带有 SHIFTJIS_CHARSET 的“Arial Unicode MS”字体提供精确(非旋转)的外观。
I have no Delphi 2006, so I tested the code on Delphi 2007; you should:
convert the string with "%" characters to plain UTF8 string;
convert UTF8 string to Wide String (UTF8Decode);
convert Wide String to Ansi String with Japanese encoding (WideCharToMultiByte):
When I tested the above code with different fonts the Japanese symbols from the fonts with names starting from '@' appeared rotated 90 degrees counterclockwise compared with the Japanese string from the question. The "Arial Unicode MS" font with SHIFTJIS_CHARSET gives exact (non-rotated) appearance.
IdURI 单元中的 Indy TIdURI 类包含 UrlDecode / UrlEncode 函数。您可以使用 Indy 的最新版本(10.5.8)进行尝试,它具有编码参数:
The Indy TIdURI class in IdURI unit contains UrlDecode / UrlEncode functions. You could try it with a recent version (10.5.8) of Indy, which has encoding parameters:
我找到了解决方案,我在这里得到了一个指针: delphigroups.info/2/5/ 209620.html然后在httpApp.pas中用HttpDecode进行实验,解决方案是:
I've found the solution, I got a pointer here: delphigroups.info/2/5/209620.html then experiment with HttpDecode in httpApp.pas, the solution is:
mjn 可能是正确的,但我强烈建议,如果您要在 Delphi 中处理任何类型的 Unicode,请尝试说服您的老板升级到最新版本的 Delphi(或只是 Delphi 2009)。 Delphi 2009 中的 Unicode 支持非常好,并且开箱即用。如果你真的做不到这一点,TNT 组件对我们有用,但最终我们只是等待 Delphi 2009 年才推出,因为从 Borland 开箱即用要简单得多。
mjn may be correct, but I would strongly advise that if you are going to be handling any kind of Unicode within Delphi, try to persuade your bosses to upgrade to the latest version of Delphi (or just Delphi 2009). The Unicode support in Delphi 2009 is very good, and just works out of the box. If you really cant do this, the TNT components worked for us but in the end we just waited for Delphi 2009 to come out because it was so much simpler to have it out of the box from Borland.