如何让字符串不转义

2024-12-02 10:15:27
推荐回答(1个)
回答1:

解决方法有两种:
第1种:





?
第2种:

/*将字串转为html格式*/
public String strToHtml(String s)
{
if (s==null||s.equals("")) return "";
s = s.replaceAll("&", "&");
s = s.replaceAll("<", "<");
s = s.replaceAll(">", ">");
s = s.replaceAll(" ", " ");
// s = s.replaceAll("/n", "
");
// s = s.replaceAll("'", "'");
return s;
}

/*将html格式转为字串*/
public String strToHtml(String s)
{
if (s==null||s.equals("")) return "";
s = s.replaceAll("&","&");
s = s.replaceAll("<","<");
s = s.replaceAll(">",">");
s = s.replaceAll(" "," ");
//s = s.replaceAll("
","/n");
//s = s.replaceAll("'","'");
return s;
}