转换与转换到& ETC

发布于 2024-08-07 20:39:55 字数 106 浏览 1 评论 0原文

我想将 & 转换为 &,将 " 转换为 " 等。 C# 中是否有一个函数可以做到这一点,而无需手动编写所有选项?

I want to convert & to &, " to " etc.
Is there a function in c# that could do that without writing all the options manually?

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

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

发布评论

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

评论(6

撩发小公举 2024-08-14 20:39:55
System.Web.HttpUtility.HtmlDecode()

编辑:来自 此处表示“要在 Web 应用程序之外对值进行编码或解码,请使用...”

System.Net.WebUtility.HtmlDecode()
System.Web.HttpUtility.HtmlDecode()

Edit: Note from here that "To encode or decode values outside of a web application, use..."

System.Net.WebUtility.HtmlDecode()
与风相奔跑 2024-08-14 20:39:55

使用静态方法

HttpUtility.HtmlEncode

& 更改为 &,将 " 更改为 "。使用

HttpUtility.HtmlDecode

做相反的事情。

Use the static method

HttpUtility.HtmlEncode

to change & to & and " to ". Use

HttpUtility.HtmlDecode

to do the reverse.

巨坚强 2024-08-14 20:39:55

您可以使用 System.Net.WebUtility.HtmlDecode(uri);

You can use System.Net.WebUtility.HtmlDecode(uri);

゛时过境迁 2024-08-14 20:39:55
using System.Web; 
...
var html = "this is a sample & string"; 
var decodedhtml = HttpUtility.HtmlDecode(html);
using System.Web; 
...
var html = "this is a sample & string"; 
var decodedhtml = HttpUtility.HtmlDecode(html);
始终不够爱げ你 2024-08-14 20:39:55

对于.NET< 4 简单编码器

    public static string HtmlEncode(string value)
    {
        return value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'");
    }

For .NET < 4 simple encoder

    public static string HtmlEncode(string value)
    {
        return value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文