티스토리 뷰

Skill/spring

[java] 변수명 camel형으로 변경

진열사랑 2020. 11. 17. 13:44

잘되네..^^

public static void main(String[] args) {
	try {
		BufferedReader br = new BufferedReader(new FileReader(new File("C:/Users/user/Documents/var_input.sql")));
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("C:/Users/user/Documents/var_output.sql")));

		String oneLine;
		while((oneLine = br.readLine()) != null) {
			String result = changeVariable(oneLine).toString();
			result = changeFirstChar(result);
			bw.write(result + "\r\n");
			bw.flush();
		}
		bw.close();
		br.close();
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
}

public static StringBuffer changeVariable(String word) {
	StringBuffer sb = new StringBuffer();
	for (String s: word.split("_")) {
		sb.append(Character.toUpperCase(s.charAt(0)));
		if (s.length() > 1) {
			sb.append(s.substring(1, s.length()).toLowerCase());
		}
	}
	return sb;
}

public static String changeFirstChar(String word) {
	return word.substring(0, 1).toLowerCase() + word.substring(1);
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함