几个String的处理方法。


    /**
     * 读取工程中的text文件
     * @param filePath
     * @return
     */
    public static List<String> readFileByLines(String filePath) {
        List<String> li = new ArrayList<String>();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(
                    filePath), "UTF-8"));
            String tempString = null;
            while ((tempString = br.readLine()) != null) {
                li.add(tempString);
            }
            br.close();
            return li;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 电话号码中间加密显示
     * @param phone
     * @return
     */
    public static String  encryptionPhoneNum(String phone){
        String encryptionphone = phone.replaceAll("(\\d{3})\\d{4}(\\d{2})","$1****$2");
        return encryptionphone;
    }
    /**
     * 邮箱前面加密
     * @param email
     * @return
     */
    public static String encryptionEmail(String email){
        String encrytionemail = email.replaceAll("(\\w[-\\w.+])*(@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14})", "$1********$2");
        return encrytionemail;
    }
    /**
     * 座机显示加密
     * @param phoneNum
     * @return 400(-\d{3,4}){2}
     */
    public static String encryptionFixedLine(String phoneNum){
        String encryptionLine="---";
        if("1".equals(isFixed400or800(phoneNum))){
            encryptionLine = phoneNum.replaceAll("([0][1-9]{0,3})(-)([0-9]{5,10})", "$1$2********");
        }else if("2".equals(isFixed400or800(phoneNum))){
            encryptionLine = phoneNum.replaceAll("(400)(-\\d{3,4}){2}", "$1-****$2");
        }else{
            encryptionLine = phoneNum.replaceAll("(800)(-\\d{3,4}){2}", "$1-****$2");
        };
        return encryptionLine;
    }
    /**
     * 判断400,800,座机
     * @param phoneNum
     * @return
     */
    public static String isFixed400or800(String phoneNum){
        String compare ="0";
        if(Pattern.matches("[0][1-9]{0,3}-[0-9]{5,10}", phoneNum)){
            compare ="1";
        }else if(Pattern.matches("400(-\\d{3,4}){2}", phoneNum)){
            compare ="2";
        }else if(Pattern.matches("800(-\\d{3,4}){2}", phoneNum)){
            compare ="3";
        }else{
            compare ="1";
        }
        return compare;
    }
    /**
     * 匹配分词中的特殊字符串后加高亮
     * @param wordStr
     * @param color
     * @return
     */
    public static String specialCharacters(String wordStr){
        if(wordStr != null && !"".equals(wordStr)){
            String regEx="[`~!@#$%^&*()+=|{}':;',//[//].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";   
            Pattern   p   =   Pattern.compile(regEx);      
            Matcher   m   =   p.matcher(wordStr);
            if(m.find()){
                return "-1";
            }
        }
        return "1";
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值