驼峰标识转下划线标识

public class Demo {
    public static void main(String[] args) throws Exception {  
        System.out.println(toTableString("sunTable"));
    }  
    /**
     * 驼峰标识转下划线标识
     * 
     * @param text
     * @return
     */
    public static String toTableString(String text) {
        String tName = text.substring(0, 1).toLowerCase();
        for (int i = 1; i < text.length(); i++) {
            if (!Character.isLowerCase(text.charAt(i))) {
                tName += "_";
            }
            tName += text.substring(i, i + 1);
        }
        return tName.toLowerCase();
    }
}
 

猜你喜欢

转载自blog.csdn.net/Sun_of_Rainy/article/details/88796770
今日推荐