text: public static string HtmlEncode(string plainText){if (string.IsNullOrEmpty(plainText)){return string.Empty;}var result = new StringBuilder(plainText.Length);for (int index = 0; index < plainText.Length; index++){char ch = plainText[index];switch (ch){case '"':result.Append("&quot;");break;case '&':result.Append("&amp;");break;case '<':result.Append("&lt;");break;case '>':result.Append("&gt;");break;case '\'':result.Append("&#x27;");break;case '/':result.Append("&#x2F;");break;default:if (ch < 128){result.Append(ch);}else{result.Append("&#").Append((int)ch).Append(";");}break;}}return result.ToString();}