代码
/// <summary>
/// convert special char to html entity
/// </summary>
/// <param name="source">source string</param>
/// <returns>target string</returns>
public static string ToHtmlEntity(string source)
{
if (string.IsNullOrEmpty(source))
{
return string.Empty;
}
string result = source.Replace("\"", """); // "
result = result.Replace("'", "'"); // '--> '
result = result.Replace("<", "<"); // <
result = result.Replace(">", ">"); // >
result = result.Replace("&", "&"); // &
return result;
}
/// convert special char to html entity
/// </summary>
/// <param name="source">source string</param>
/// <returns>target string</returns>
public static string ToHtmlEntity(string source)
{
if (string.IsNullOrEmpty(source))
{
return string.Empty;
}
string result = source.Replace("\"", """); // "
result = result.Replace("'", "'"); // '--> '
result = result.Replace("<", "<"); // <
result = result.Replace(">", ">"); // >
result = result.Replace("&", "&"); // &
return result;
}