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

    return source.toUpperCase();
  }
Exemplo n.º 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();
 }
Exemplo n.º 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());
 }
Exemplo n.º 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;
 }
Exemplo n.º 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(), "__");
 }