替换特殊符号
Posted 胡子就不刮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了替换特殊符号相关的知识,希望对你有一定的参考价值。
public class BaseReplaceString { /* < < 小于号或显示标记 > > 大于号或显示标记 & & 可用于显示其它特殊字符 " " 引号 ? ? 已注册 ? ? 版权 ? ? 商标 ? ? 半个空白位 ? ? 一个空白位 不断行的空白*/ private static String[] htmlSpecialCharacter = new String[]{"<", ">", "&", "?", "?", "?", "?", "?", " "}; private static String[] commonSpecialCharacter = new String[]{"<", ">", "&", "\"", "‘", " ", "!", "@", "#", "\\$", "%", "\\*", "\\^", "\\(", "\\)", "_", "\\+", "\\=", "\\-", ",", "\\.", ",", "。", "\\?", "`", "~","《","》",".com",".cn",".net","org","www"}; /** * 过滤html特殊字符 * @param specialCharacterStr * @return */ public static String htmlSpecialCharacterRemover(String specialCharacterStr) { int length = htmlSpecialCharacter.length; for (int i = 0; i < length; i++) { specialCharacterStr = specialCharacterStr.replace(htmlSpecialCharacter[i], ""); } return specialCharacterStr; } /** * 过滤普通的特殊字符 * @param specialCharacterStr * @return */ public static String commonsSpecialCharacterRemover(String specialCharacterStr) { int length = commonSpecialCharacter.length; for (int i = 0; i < length; i++) { specialCharacterStr = specialCharacterStr.replace(commonSpecialCharacter[i], ""); } return specialCharacterStr; } /** * 所有特殊字符替换 * @param specialCharacterStr * @return */ public static String specialCharacterRemover(String specialCharacterStr) { specialCharacterStr = htmlSpecialCharacterRemover(specialCharacterStr); specialCharacterStr = commonsSpecialCharacterRemover(specialCharacterStr); return specialCharacterStr; } }
公司评论这块不仅需要判断敏感字还需要对内容做一些特殊处理,今天整理下,以后可以留着用
以上是关于替换特殊符号的主要内容,如果未能解决你的问题,请参考以下文章