在 HTML 中显示文字
我需要在 HTML 页面中显示一些文字文本(它由应用程序自动生成。我用 C# 编写。)
<TR>
<TD VALIGN="center" ALIGN="center"><B>398</B></TD>
<TD VALIGN="center">Name: <B>' an image.jpg</B></TD>
<TD><IMG SRC="Images/' an image.jpg"ALT=' an image.jpg></TD>
</TR>
“ ' ”字符导致了问题,因为它是 HTML 转义字符。 (文件名中还使用了其他转义字符。)我无法更改文件名。那么如何在 HTML 页面中显示文字呢?
I need to display some literal text in my HTML page (it's automatically generated by an application. I wrote in C#.)
<TR>
<TD VALIGN="center" ALIGN="center"><B>398</B></TD>
<TD VALIGN="center">Name: <B>' an image.jpg</B></TD>
<TD><IMG SRC="Images/' an image.jpg"ALT=' an image.jpg></TD>
</TR>
The " ' " character causes the problem, because it's a HTML escape character. (There are also other escape characters used in file names.) I can't change the file names. So how can I display the literal text in my HTML page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代替使用
。
这里是 HTML 实体和编码的参考 (http://www.zytrax.com/tech/web/entities.html)
Use
instead.
Here is reference to HTML Entities and Codings (http://www.zytrax.com/tech/web/entities.html)
编辑:如果是 Windows 窗体,您可以使用:
有必要在项目中添加对 System.Web.dll 的引用。请记住,在 HTML 中,属性应该用引号 char " 括起来,而不是用 apex,
'
括起来。您可以简单地使用该
方法;此外,
'
不是问题,也许它可以是引号、"
或<
和>
字符。以下示例对字符串进行编码以通过 HTTP 传输。它对名为 TestString 的字符串进行编码,其中包含文本
"This is a."
,并将其复制到名为 EncodedString 的字符串中,如"This is a <测试字符串>."
。C#:
EDIT: in case of Windows Forms, you can use:
It is necessary to add a reference to
System.Web.dll
in your project. Remember that in HTML the attributes should be enclosed with the quote char " and not with apex,'
.You can simply use the
method; moreover, the
'
is not the problem, maybe it can be the quote,"
, or<
and>
characters.The following example encodes a string for transmission by HTTP. It encodes the string named TestString, which contains the text
"This is a <Test String>."
, and copies it into the string named EncodedString as"This is a <Test String>."
.C#: