zoukankan      html  css  js  c++  java
  • 正则表达式的简单运用

        /**
         * @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;
        }
  • 相关阅读:
    SpringAOP-基于@AspectJ的简单入门
    SpringAOP-切面优先级
    Commons_IO_FileUtils的使用
    java_IO_装饰器
    java_IO_3
    java_IO_2
    java_IO_1
    App Inventor
    java学习_5_24
    java学习_5_23
  • 原文地址:https://www.cnblogs.com/lxh520/p/8418350.html
Copyright © 2011-2022 走看看