/// <summary>
/// HTML编码
/// </summary>
/// <param name="Htmlstring"></param>
/// <returns></returns>
private static Regex reg = new Regex(@"[<>&\r\n\t ]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static string HtmlCode(string s)
{
s = reg.Replace(s, new MatchEvaluator(delegate(Match m)
{
switch (m.ToString())
{
case "<":
return "<";
case ">":
return ">";
case "&":
return "&";
case "\r":
return "\r";
case "\n":
return "\n<br />";
case "\t":
return " ";
case " ":
return " ";
default:
return m.ToString();
}
}));
return s;
}