Converting & to & etc

痴心易碎 提交于 2019-11-30 04:37:27
System.Web.HttpUtility.HtmlDecode()

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

System.Net.WebUtility.HtmlDecode()

Use the static method

HttpUtility.HtmlEncode

to change & to & and " to ". Use

HttpUtility.HtmlDecode

to do the reverse.

Corredera Romain

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

A good article about this subject : Different ways how to escape an XML string in C#

Alex W.
using System.Web; 
...
var html = "this is a sample & string"; 
var decodedhtml = HttpUtility.HtmlDecode(html);

For .NET < 4 simple encoder

    public static string HtmlEncode(string value)
    {
        return value.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!