版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
StringHelper.java
import org.apache.commons.lang.StringEscapeUtils; public class StringHelper { public static void main(String[] args) { // 转义 StringEscapeUtils.escapeSql(""); // commons-lang3没有sql StringEscapeUtils.escapeHtml(""); StringEscapeUtils.escapeJavaScript(""); StringEscapeUtils.escapeJava(""); StringEscapeUtils.escapeCsv(""); StringEscapeUtils.escapeXml(""); // 反转义 StringEscapeUtils.unescapeHtml(""); StringEscapeUtils.unescapeJavaScript(""); StringEscapeUtils.unescapeJava(""); StringEscapeUtils.unescapeCsv(""); StringEscapeUtils.unescapeXml(""); } /** * 特殊字符转换 * * @param str * @return */ public static String StringEscape(String str) { if (str == null) return null; str = str.replace("'", "‘"); str = str.replace(";", ";"); str = str.replace(",", ","); str = str.replace("?", "?"); str = str.replace("<", "<"); str = str.replace(">", ">"); str = str.replace("(", "("); str = str.replace(")", ")"); str = str.replace("@", "@"); str = str.replace("=", "="); str = str.replace("+", "+"); str = str.replace("*", "*"); str = str.replace("&", "&"); str = str.replace("#", "#"); str = str.replace("%", "%"); str = str.replace("$", "$"); str = str.replaceAll("[\\t\\n\\r]", ""); // \t为制表符 \n为换行 \r为回车 return str; } }
相关jar包下载
原文链接:https://www.idaobin.com/archives/2060.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告