package tutorialJava.examenes.examen20241122;

public class EjD_StringDeCamelCaseASnakeCase {

	public static void main(String[] args) {
		String str = "estoEsUnEjemploDeNombreDeVariable";

		System.out.println("snake_case: " + camelCaseASnakeCase(str));
	}

	/**
	 * 
	 * @param strCamelCase
	 * @return
	 */
	public static String camelCaseASnakeCase(String strCamelCase) {
		String strSnakeCase = "";
		
		for (int i = 0; i < strCamelCase.length(); i++) {
			if (strCamelCase.charAt(i) >= 'A' && 
					strCamelCase.charAt(i) <= 'Z') {
				strSnakeCase += "_" + 
					((char) (strCamelCase.charAt(i) + 32));
			}
			else {
				strSnakeCase += strCamelCase.charAt(i);
			}
		}
		return strSnakeCase;
	}
}
