码迷,mamicode.com
首页 > 其他好文 > 详细

替换特殊符号

时间:2016-12-26 21:41:20      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:err   net   公司   remove   大于号   com   turn   character   注册   

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;
    }

}

 

公司评论这块不仅需要判断敏感字还需要对内容做一些特殊处理,今天整理下,以后可以留着用

 

替换特殊符号

标签:err   net   公司   remove   大于号   com   turn   character   注册   

原文地址:http://www.cnblogs.com/hzzjj/p/6223905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!