因此需要以下函数做转换:

复制代码 代码如下:

///<summary>

///替换html中的特殊字符

///</summary>

///<paramname=”theString”>需要进行替换的文本。</param>

///<returns>替换完的文本。</returns>

public static string HtmlEncode(string theString)

{

theString=theString.Replace(“>”,”&gt;”);

theString=theString.Replace(“<“,”&lt;”);

theString=theString.Replace(” “,”&nbsp;”);

theString=theString.Replace(“\””,”&quot;”);

theString = theString.Replace(“\'”, “'”);

theString=theString.Replace(“\n”,”<br/>”);

return theString;

}

///<summary>

///恢复html中的特殊字符

///</summary>

///<paramname=”theString”>需要恢复的文本。</param>

///<returns>恢复好的文本。</returns>

public static string HtmlDiscode(string theString)

{

theString=theString.Replace(“&gt;”,”>”);

theString=theString.Replace(“&lt;”,”<“);

theString=theString.Replace(“&nbsp;”,” “);

theString=theString.Replace(“&quot;”,”\””);

theString = theString.Replace(“'”, “\'”);

theString=theString.Replace(“<br/>”,”\n”);

return theString;

}

您可能感兴趣的文章:

  • C#实现过滤html标签并保留a标签的方法
  • 使用C#获取网页HTML源码的例子
  • C#中Html.RenderPartial与Html.RenderAction的区别分析
  • c#使用htmlagilitypack解析html格式字符
  • c#远程html数据抓取实例分享
  • C#下解析HTML的两种方法介绍
  • C#将html table 导出成excel实例
  • C#中除去所有在HTML元素中标记
  • C#实现压缩HTML代码的方法
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。