如何转义HTML字符?在.NET中-& gt;& amp; quot; [英] How do i escape HTML characters? in .NET --> "

查看:72
本文介绍了如何转义HTML字符?在.NET中-& gt;& amp; quot;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在.NET中转义HTML字符?

How do i escape HTML characters in .NET?

我正在从json字符串中获取html,并且在标题中我得到了& quot;更多文本.看来我需要做两次才能使& amp;"成为& quot ,然后成为'"'.

I am grabbing html from a json string and in the title i get "more text. It looks like i need to do it twice to get " to become " then that to be a '"'.

如何在.NET中转义所有文本html转义代码?

How do i escape all the text html escape codes in .NET?

推荐答案

如果必须执行两次,则说明您对源字符串进行了双重编码,因此必须对它进行双重解码才能返回到原始(未编码))字符串.

If you have to do it twice, then you have double encoded your source string, and so you have to double decode it to get back to the original (unencoded) string.

您可以将 System.Web.HttpUtility.HtmlEncode() HtmlDecode()用于这些目的.

You can use System.Web.HttpUtility.HtmlEncode() and HtmlDecode() for these purposes.

这篇关于如何转义HTML字符?在.NET中-& gt;& amp; quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆