package com.jerome.utils.file;
/**
* HtmlUtils <br>
* Function: Html标签和string的相互转换
*
* @author Jerome Song
*/
public class HtmlUtils {
/**
* 把html标签转换成String类能够承载的
*
* @param str
* @return
*/
public static String htmlToString(String str) {
if (str == null)
return "";
if (str.equals(""))
return "";
str = str.replaceAll("&", "&");
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll("&", "&");
str = str.replaceAll(""", """);
str = str.replaceAll("\"", """);
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll(" ", " ");
return str;
}
/**
* 把String转换成html标签
*
* @param str
* @return
*/
public static String stringToHtml(String str) {
if (str == null)
return "";
if (str.equals(""))
return "";
str = str.replaceAll("&", "&");
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll(""", "\"");
str = str.replaceAll(" ", " ");
return str;
}
}