JavaでHtmlの特殊符号文字列のencodeとdecodeのサンプルコード

Javaコード下記
public static String encode(String value) {
String htmltext = “";
if (value != null) htmltext = “" + value;
htmltext = htmltext.replaceAll(“\\&", “&");
htmltext = htmltext.replaceAll(“<“, “&lt;");
htmltext = htmltext.replaceAll(“>", “&gt;");
htmltext = htmltext.replaceAll(“\"", “&quot;");
return htmltext;
}
public static String decode(String value) {
String htmltext = “";
if (value != null) htmltext = “" + value;
htmltext = htmltext.replaceAll(“\\&quot;", “\"");
htmltext = htmltext.replaceAll(“\\&gt;", “>");
htmltext = htmltext.replaceAll(“\\&lt;", “<“);
htmltext = htmltext.replaceAll(“\\&amp;", “&");
return htmltext;
}

Java

Posted by arkgame