zoukankan      html  css  js  c++  java
  • 替换特殊符号

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

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

  • 相关阅读:
    Certificate、Provisioning Profile、App ID
    boundingRectWithSize
    IOS照片框架
    UIlabel 属性text
    UIMenuController的使用,对UILabel拷贝以及定制菜单
    iOS 自定义emoji表情键盘
    IOS第三方字体
    IOS 验证码
    网上收集的以及自己总结的iOS开发技巧
    给自己一个坚持下去的理由
  • 原文地址:https://www.cnblogs.com/hzzjj/p/6223905.html
Copyright © 2011-2022 走看看