C HTML character conversion function sharing
- 2020-05-17 05:09:17
- OfStack
Therefore, the following functions are required for conversion:
///<summary>
/// replace html Special characters in
///</summary>
///<paramname="theString"> The text that needs to be replaced. </param>
///<returns> Replace the finished text. </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>
/// restore html Special characters in
///</summary>
///<paramname="theString"> Text that needs to be recovered. </param>
///<returns> Restore good text. </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;
}