如何转换符号-》 † ”到 HTML 代码?
我正在尝试将匕首“†”符号写入 HTML 页面,该页面会转换为 PDF 文档,但这在 PDF 上显示为“”
我知道我需要使用此符号的 HTML 代码,其中是†
。
我已经成功地为“€”完成了此操作,但在这些情况下,我将代码直接写入 HTML 中。在本例中,我从 XML 文件中读取符号。当我检查包含该符号的变量的值时,它显示为“†”。
我应该注意到我已经尝试阅读符号 & XML 文件中的代码如下:
<fund id="777" countryid="N0" append="†" />
and
<fund id="777" countryid="N0" append="†" />
但两者都作为符号存储在变量中,当我将它们写入页面时,两者都呈现为“”。另外,我尝试了以下方法:
string code = "†";
string symbol = "†";
string htmlEncodedCode = HttpUtility.HtmlEncode(code);
string htmlEncodedSymbol = HttpUtility.HtmlEncode(symbol);
tc.Text = fund.Name + code + " " + symbol + " " +
htmlEncodedCode + " " + htmlEncodedSymbol;
但只有第一个有效。它在文档中显示为:
FundName† †† â€
有人可以建议我如何让它发挥作用吗?
更新:
@James Curran 下面的答案是正确的。为了清楚起见,我必须将 XML 更改为:
<fund id="777" countryid="N0" append="&dagger;" />
在我的 C# 中:
tc.Text = fund.Name + append;
I'm trying to write the dagger '†' symbol to a HTML page which gets converted to a PDF document, but this appears on the PDF as 'â€'
I understand that I need to use the HTML code for this symbol, which is †
.
I've done this successfully for the '€' but in these cases I've written the code directly into the HTML. In this case, I'm reading the symbol from an XML file. When I inspect the value of the variable that contains the symbol, it appears as '†'.
I should note that I've tried reading the symbol & the code from the XML file, as follows:
<fund id="777" countryid="N0" append="†" />
and
<fund id="777" countryid="N0" append="†" />
but both are stored in the variable as the symbol, and when I write them to the page, both are rendered as 'â€'. Also, I've tried the following:
string code = "†";
string symbol = "†";
string htmlEncodedCode = HttpUtility.HtmlEncode(code);
string htmlEncodedSymbol = HttpUtility.HtmlEncode(symbol);
tc.Text = fund.Name + code + " " + symbol + " " +
htmlEncodedCode + " " + htmlEncodedSymbol;
but only the first works. It appears in the document as:
FundName† †† â€
Can somebody suggest how I can get this to work?
Update:
@James Curran's answer below was correct. Just for the sake of clarity, I had to change the XML to:
<fund id="777" countryid="N0" append="†" />
and in my C#:
tc.Text = fund.Name + append;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该符号通常被称为“匕首”,在 html 中由实体表示:
&匕首;
†That symbol is generally known as a "dagger" and is represented in html by the entity:
†
†这是一个编码问题。 ” 可能是 UTF-8 中匕首的 Latin-1 表示。尝试将 dagger 从 UTF-8 转换为 ISO-8859-1。
This is an encoding issue. †is probably the Latin-1 representation of the dagger in UTF-8. Try converting the dagger from UTF-8 to ISO-8859-1.
对于 XML 文件,您可能想要执行以下操作:
原因是 XML 文件会将
&
解释为 & 。符号,其余为文字文本。因此,在您的 html 中,您将得到†
,这应该可以。With the XML file what you probably want to do is something along the lines of:
The reason is that the XML file will interpret the
&
as the & symbol and the rest as literal text. Thus in your html you will get†
and that should do you.