【发布时间】:2021-08-18 08:30:50
【问题描述】:
我有一个使用 Expression Web 4 构建的网页“index.html”,其中包含一个以 id 分隔的值:
<html>
<head></head>
<body>
<... some html code ...>
<!--MYVALUEID-->
Dernières News
<... some html code ...>
</body>
</html>
使用我的 delphi 应用程序,我在 TStringList 中加载页面并将值读取到 TEDIT:
S:=TStringList.Create;
S.LoadFromFile('path\index.html');
Edit1.Text:=S[S.IndexOf('<!--MYVALUEID-->')+1];
S.Free;
问题是重音字符,因为我在 TEDIT 中得到了这个:“Dernières News”
在 Expression Web 代码中,文本是正确的:Dernières News
当我在记事本中打开 index.html 时,它会显示:Dernières News
记事本中的文件显示为UTF8
当我使用 HTTPApp.HTMLDecode() 时,我得到了:Dernières News
还有 System.NetEncoding、TNetEncoding.HTML.Decode :Dernières News
是否有可靠的例程来解码html特殊字符转换?
我在 SO 中检查了许多问题并尝试了上述解决方案,但没有任何反应。
提前谢谢,我卡住了。
【问题讨论】:
-
您可能正在使用 Delphi 7,因此字符串是 ANSI 编码的,您无需采取任何措施来处理 UTF8。但这只是一个猜测。没有细节猜测是我们所能做的。
-
@DavidHeffernan OP 提到了
System.NetEncoding.TNetEncoding,直到 Delphi XE7 才存在
标签: html delphi special-characters decode