humpToUnderline
/** * 驼峰转下划线 * @param humpString * created by hbd 20160722 * @return */ public String humpToUnderline(String humpString) { if(BlankUtil.isEmpty(humpString)) return ""; String regexStr = "[A-Z]"; Matcher matcher = Pattern.compile(regexStr).matcher(humpString); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String g = matcher.group(); matcher.appendReplacement(sb, "_" + g.toLowerCase()); } matcher.appendTail(sb); if (sb.charAt(0) == ‘_‘) { sb.delete(0, 1); } return sb.toString(); }
时间: 2024-10-19 19:12:02