예제 #1
0
  /**
   * 转成大写字符
   *
   * @param source
   * @return
   */
  public static String UpperCase(String source) {
    if (StringUtil.isEmpty(source)) {
      return "";
    }

    return source.toUpperCase();
  }
예제 #2
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();
 }
예제 #3
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());
 }
예제 #4
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;
 }
예제 #5
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(), "__");
 }