特殊字符 转义对照。如 < >

一般是html的转义,xml也适用
但是在写sql时,xml文件中会出现。







转义方法
public static String htmlReplace(String str){ str = str.replace("“","&ldquo;"); str = str.replace("”","&rdquo;"); str = str.replace(" ","&rdquo;"); str = str.replace("&amp;","&"); str = str.replace("'","&#39;"); str = str.replace("’","&rsquo;"); str = str.replace("—","&mdash;"); str = str.replace("–","&ndash;"); str = str.replace("<","&lt;"); str = str.replace(">","&gt;"); return str; }
posted @ 2022-10-19 11:27  了悟  阅读(746)  评论(0编辑  收藏  举报