.Net 函数替换/编码和解码字符串中的 HTML 字符
我有以下代码:
Dim lStatementText As String
Dim lStatementString As New System.Text.StringBuilder
lStatementString.Append(RndRes.Forms.txt_request)
lStatementString.Append(" ")
lStatementString.Append("<b><a>")
lStatementString.Append(Request.ID)
lStatementString.Append("</a> - <a>")
lStatementString.Append(Request.Description)
lStatementString.Append("</a></b> ")
lStatementString.Append(RndRes.Forms.txt_IsNotYetLoaded)
lStatementString.Append(". ")
lStatementString.Append(RndRes.Forms.txt_click)
lStatementString.Append(" <b><a>")
lStatementString.Append(RndRes.Forms.txt_here)
lStatementString.Append(" </a></b> ")
lStatementString.Append(RndRes.Forms.txt_GetFromDB)
lStatementText = lStatementString.ToString()
Dim lLink As New Infragistics.Win.FormattedLinkLabel.UltraFormattedLinkLabel()
lLink.Value = lStatementText
lLink.TreatValueAs = FormattedLinkLabel.TreatValueAs.FormattedText
AddHandler lLink.LinkClicked, AddressOf OnLinkClicked
其中 Request.ID、Request.Description 以及 RndRes.Forms.txt_* 都是字符串。我想在 Infragistics FormattedLinkLabel 中显示我在此处构建的字符串。问题是,如果 Request 类中的任何字符串包含 HTML 字符,则标签将无法正确显示,并且 HTML 编码会被破坏。 我需要找到一个屏蔽 HTML 代码的函数。
I have the following code:
Dim lStatementText As String
Dim lStatementString As New System.Text.StringBuilder
lStatementString.Append(RndRes.Forms.txt_request)
lStatementString.Append(" ")
lStatementString.Append("<b><a>")
lStatementString.Append(Request.ID)
lStatementString.Append("</a> - <a>")
lStatementString.Append(Request.Description)
lStatementString.Append("</a></b> ")
lStatementString.Append(RndRes.Forms.txt_IsNotYetLoaded)
lStatementString.Append(". ")
lStatementString.Append(RndRes.Forms.txt_click)
lStatementString.Append(" <b><a>")
lStatementString.Append(RndRes.Forms.txt_here)
lStatementString.Append(" </a></b> ")
lStatementString.Append(RndRes.Forms.txt_GetFromDB)
lStatementText = lStatementString.ToString()
Dim lLink As New Infragistics.Win.FormattedLinkLabel.UltraFormattedLinkLabel()
lLink.Value = lStatementText
lLink.TreatValueAs = FormattedLinkLabel.TreatValueAs.FormattedText
AddHandler lLink.LinkClicked, AddressOf OnLinkClicked
Where Request.ID, Request.Description and also RndRes.Forms.txt_* are all strings. I want to display the string I build up here in a Infragistics FormattedLinkLabel. The problem is that if any of the strigs from the Request class contains a HTML character, the label is not displayed properly and the HTML encoding is broken.
I need to find a function that masks the HTML codes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您手头没有 HttpContext 对象,请查看 HttpUtility.HtmlEncode:
http://msdn.microsoft.com/en-us/library/73z22y6h.aspx
If you don't have an HttpContext object at hand, look at HttpUtility.HtmlEncode:
http://msdn.microsoft.com/en-us/library/73z22y6h.aspx
尝试 Server.HtmlEncode() 和 Server.HtmlDecode(),http://msdn .microsoft.com/en-us/library/hwzhtkke.aspx
Try Server.HtmlEncode() and Server.HtmlDecode(), http://msdn.microsoft.com/en-us/library/hwzhtkke.aspx