public final static String htmlEncode(String plainText){if (plainText == null || plainText.length() == 0){return "";}StringBuilder result = new StringBuilder(plainText.length());for (int index=0; index<plainText.length(); index++){char ch = plainText.charAt(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:result.append(ch);}}return result.toString();}
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();}