因此需要以下函數(shù)做轉(zhuǎn)換:
復(fù)制代碼 代碼如下:
///summary>
///替換html中的特殊字符
////summary>
///paramname="theString">需要進(jìn)行替換的文本。/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("\'", "#39;");
theString=theString.Replace("n","br/>");
return theString;
}
///summary>
///恢復(fù)html中的特殊字符
////summary>
///paramname="theString">需要恢復(fù)的文本。/param>
///returns>恢復(fù)好的文本。/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("#39;", "'");
theString=theString.Replace("br/>","\n");
return theString;
}
您可能感興趣的文章:- C#實(shí)現(xiàn)過(guò)濾html標(biāo)簽并保留a標(biāo)簽的方法
- 使用C#獲取網(wǎng)頁(yè)HTML源碼的例子
- C#中Html.RenderPartial與Html.RenderAction的區(qū)別分析
- c#使用htmlagilitypack解析html格式字符串
- c#遠(yuǎn)程html數(shù)據(jù)抓取實(shí)例分享
- C#下解析HTML的兩種方法介紹
- C#將html table 導(dǎo)出成excel實(shí)例
- C#中除去所有在HTML元素中標(biāo)記
- C#實(shí)現(xiàn)壓縮HTML代碼的方法