Java 驼峰转下划线


public static String camelCase2LineSeparation(String camelWord) {
		Matcher matcher = Pattern.compile("([A-Z][a-z])|([a-z][A-Z])").matcher(camelWord);

		StringBuffer word = new StringBuffer();
		while (matcher.find()){			
			matcher.appendReplacement(word, matcher.group(0).replaceAll("(.$)", "_$1"));
		}
		matcher.appendTail(word);

		return  word.toString().toUpperCase();
}
public static String upperCamelCase2LineSeparation(String upperCamelWord) {
		Matcher matcher = Pattern.compile("[A-Z]").matcher(upperCamelWord);

		StringBuffer word = new StringBuffer();
		while (matcher.find()){
			matcher.appendReplacement(word, matcher.group(0).toUpperCase() + "_");
		}
		matcher.appendTail(word);

		return word.toString().toUpperCase();
}
posted @ 2019-12-20 15:55  GoodByeZ  阅读(479)  评论(0编辑  收藏  举报