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

正则表达式的简单运用

时间:2018-02-05 18:42:17      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:mil   bsp   ==   exti   public   tran   substr   style   replace   

    /**
     * @return 请求批次编号(yyyyMMddhhmmss+6位随机数)
     */
    public static String  getRandomNum(){
        String  code="";
        Random random = new Random();
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        String temp= timestamp.toString().replaceAll("[- :]", "").substring(0, 14);
        for (int i = 0; i < 6; i++) {
            code += random.nextInt(9);
        }
        return temp+code;
    }
    
    /**
     * 处理格式
     *  ""  "3045056,3045057"  "3045056,3045057,3045058"
     * @param str
     * @return
     */
    public String  putGother(String str){
        str = str.replaceAll(",{2,}", ","); //替换多个,
        if (str.indexOf(",")==0) {
            str = str.substring(1, str.length()); 
        }
        if (str.lastIndexOf(",")>0) {
            str = str.substring(0, str.length()-1); 
        }
        return str;
    }

 

正则表达式的简单运用

标签:mil   bsp   ==   exti   public   tran   substr   style   replace   

原文地址:https://www.cnblogs.com/lxh520/p/8418350.html

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