JAVA驼峰转下划线

 

 

 private static Pattern humpPattern = Pattern.compile("[A-Z]");

    /**
     *  驼峰转下划线
     * @param str
     * @return
     */
    public static String humpToLine(String str) {
        Matcher matcher = humpPattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }
        matcher.appendTail(sb);
        String substring = sb.toString().substring(1);
        return substring;
    }

 

posted @ 2020-11-23 17:33  yvioo  阅读(2760)  评论(2编辑  收藏  举报