如何转换符号-》 † ”到 HTML 代码?

发布于 2024-09-12 20:29:11 字数 1133 浏览 0 评论 0原文

我正在尝试将匕首“†”符号写入 HTML 页面,该页面会转换为 PDF 文档,但这在 PDF 上显示为“”

我知道我需要使用此符号的 HTML 代码,其中是†

我已经成功地为“€”完成了此操作,但在这些情况下,我将代码直接写入 HTML 中。在本例中,我从 XML 文件中读取符号。当我检查包含该符号的变量的值时,它显示为“†”。

我应该注意到我已经尝试阅读符号 & XML 文件中的代码如下:

<fund id="777" countryid="N0" append="&#8224;" />

and

<fund id="777" countryid="N0" append="†" />

但两者都作为符号存储在变量中,当我将它们写入页面时,两者都呈现为“”。另外,我尝试了以下方法:

string code = "&#8224;";
string symbol = "†";
string htmlEncodedCode = HttpUtility.HtmlEncode(code);
string htmlEncodedSymbol = HttpUtility.HtmlEncode(symbol);

tc.Text = fund.Name + code + " " + symbol + " " + 
    htmlEncodedCode + " " + htmlEncodedSymbol;

但只有第一个有效。它在文档中显示为:

FundName† †&#8224; â€

有人可以建议我如何让它发挥作用吗?

更新:

@James Curran 下面的答案是正确的。为了清楚起见,我必须将 XML 更改为:

<fund id="777" countryid="N0" append="&amp;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="&dagger;" /> 

and in my C#:

tc.Text = fund.Name + append;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍景流年 2024-09-19 20:29:11

该符号通常被称为“匕首”,在 html 中由实体表示:
&匕首;

That symbol is generally known as a "dagger" and is represented in html by the entity:

淡淡の花香 2024-09-19 20:29:11

这是一个编码问题。 ” 可能是 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.

辞慾 2024-09-19 20:29:11

对于 XML 文件,您可能想要执行以下操作:

<fund id="777" countryid="N0" append="&#8224;" />

原因是 XML 文件会将 & 解释为 & 。符号,其余为文字文本。因此,在您的 html 中,您将得到 ,这应该可以。

With the XML file what you probably want to do is something along the lines of:

<fund id="777" countryid="N0" append="&#8224;" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文