Exemple #1
0
 public static String fixPath(String path) {
   String tempPath = path;
   if (isNotEmpty(tempPath)) {
     tempPath = StringUtil.replace(tempPath, "\\", "/");
     tempPath = StringUtil.endsWithIgnoreCase(tempPath, "/") ? tempPath : (tempPath + "/");
   }
   return tempPath;
 }
Exemple #2
0
 public static String getImgStr(String htmlStr) {
   String imrUrl = "";
   if (StringUtil.isNull(htmlStr)) {
     return "";
   }
   Matcher matcher = PATTERN.matcher(htmlStr);
   List<String> list = new ArrayList<String>();
   while (matcher.find()) {
     String group = matcher.group(1);
     if (group == null) {
       continue;
     }
     if (group.startsWith("'")) {
       list.add(group.substring(1, group.indexOf("'", 1)));
     } else if (group.startsWith("\"")) {
       list.add(group.substring(1, group.indexOf("\"", 1)));
     } else {
       list.add(group.split("\\s")[0]);
     }
   }
   for (int i = 0; i < list.size(); i++) {
     if (list.size() == 1) {
       imrUrl = list.get(i);
     } else {
       imrUrl = imrUrl + list.get(i) + "$";
     }
   }
   return imrUrl;
 }
Exemple #3
0
  /**
   * 转成大写字符
   *
   * @param source
   * @return
   */
  public static String UpperCase(String source) {
    if (StringUtil.isEmpty(source)) {
      return "";
    }

    return source.toUpperCase();
  }
Exemple #4
0
 /**
  * 转下划线模式为大小写模式(大写开头)(下划线后第一个字母改为大写,首字母大写其余全小写)
  *
  * @param source
  * @return
  */
 public static String HeadUpperCase(String source) {
   if (StringUtil.isEmpty(source)) {
     return "";
   }
   StringBuilder sb = new StringBuilder();
   sb.append(upperCase(source.substring(0, 1))).append(source.substring(1));
   return sb.toString();
 }
Exemple #5
0
  public static void main(String[] args) throws InterruptedException {
    //      StringUtil t = new StringUtil();
    //      t.new PrintA().start();
    //      //下面两行如果不加volatile的话,执行的先后顺序是不可预测的。并且下面两行都是原子操作,但是这两行作为一个整体的话就不是一个原子操作。
    //      t.a = 48; //这是一个原子操作,但是其结果不一定具有可见性。加上volatile后就具备了可见性。
    //      t.ready = true;//同理
    String imgUrl = "17930234852";

    System.out.println(StringUtil.isMobileNO(imgUrl));
  }
Exemple #6
0
 public static boolean isNumeric(String str) {
   if (StringUtil.isNull(str)) {
     return false;
   }
   for (int i = str.length(); --i >= 0; ) {
     int chr = str.charAt(i);
     if (chr < 48 || chr > 57) return false;
   }
   return true;
 }
Exemple #7
0
 public static boolean isValidPhone(String phone) {
   if (!StringUtil.isNumeric(phone)) {
     return false;
   }
   ;
   if (trim(phone).length() != 11) {
     return false;
   }
   return true;
 }
Exemple #8
0
 /**
  * 转下划线模式为大小写模式(小写开头)(下划线后第一个字母改为大写,其余全小写)
  *
  * @param source
  * @return
  */
 public static String camelLowerCase(String source) {
   if (StringUtil.isEmpty(source)) {
     return "";
   }
   String[] parts = split(source, "_");
   StringBuilder sb = new StringBuilder();
   for (String part : parts) {
     sb.append(capitalize(lowerCase(part)));
   }
   return uncapitalize(sb.toString());
 }
Exemple #9
0
 /**
  * 格式化数字
  *
  * @param str
  * @param pattern
  * @return
  */
 public static String toDecimalFormat(String str, String pattern) {
   if (StringUtil.isEmpty(pattern)) {
     return str;
   }
   DecimalFormat fmt = new DecimalFormat(pattern);
   fmt.setGroupingUsed(true);
   String outStr = null;
   double d;
   try {
     d = Double.parseDouble(str);
     outStr = fmt.format(d);
   } catch (Exception e) {
   }
   return outStr;
 }
Exemple #10
0
 /**
  * 转大小写模式为小写下划线模式(非首大写转下划线,全小写)
  *
  * @param source
  * @return
  */
 public static String unCamelLowerCase(String source) {
   if (StringUtil.isEmpty(source)) {
     return "";
   }
   String[] parts = split(source, "_");
   StringBuilder sb = new StringBuilder();
   for (String part : parts) {
     sb.append(capitalize(part));
   }
   source = capitalize(sb.toString());
   Pattern p = Pattern.compile("([A-Z]?[a-z0-9]*)");
   Matcher m = p.matcher(source);
   sb = new StringBuilder();
   while (m.find()) {
     sb.append(lowerCase(m.group())).append("_");
   }
   return substringBefore(sb.toString(), "__");
 }