public static String HtmlEncodeSymbols(string sourceString)
{
StringBuilder NewVal = new StringBuilder();
if (!String.IsNullOrEmpty(sourceString))
{
for (int x = 0; x < sourceString.Length; x++)
{
string newCh = HttpUtility.HtmlEncode(sourceString.Substring(x, 1));
if (newCh == "™") { newCh = "™"; } //Handle HtmlEncode's issue with the trademark symbol.
if (newCh.Length > 1 && (Int32)sourceString[x] > 126)
{
NewVal.Append(newCh);
}
else
{
NewVal.Append(sourceString[x]);
}
}
}
for (int x = 0; x < HtmlSpecialCharacters.Length; x += 2)
{
NewVal.Replace(HtmlSpecialCharacters[x + 1], HtmlSpecialCharacters[x]);
}
return NewVal.ToString();
}