因此需要以下函數做轉換:
復制代碼 代碼如下:
///<summary>
///替換html中的特殊字符
///</summary>
///<paramname="theString">需要進行替換的文本。</param>
///<returns>替換完的文本。</returns>
public static string HtmlEncode(string theString)
{
theString=theString.Replace(">",">");
theString=theString.Replace("<","<");
theString=theString.Replace(" "," ");
theString=theString.Replace("\"",""");
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(">",">");
theString=theString.Replace("<","<");
theString=theString.Replace(" "," ");
theString=theString.Replace(""","\"");
theString = theString.Replace("'", "\'");
theString=theString.Replace("<br/>","\n");
return theString;
}