It is necessary to write a program that checks if there is a underscore in the line, if it is, check the character following it and find out what register it is in. If the next character after an underscore is in uppercase, then change it to a lowercase character. For example, there is the string myNew_Nar if the myNew_Nar N in upper case, then replace it with a myNew_nar in lower case and output the modified string myNew_nar . I managed to change only the symbol itself. And how to display the modified string? Is it possible to use regular expressions?

  String string = "hello_World_Hi"; String s = "_"; int length = string.length(); char c = ' '; if (string.contains(s)) { for (int i = 0; i < length; i++) { if (string.charAt(i) == '_') { if (true) { c = string.charAt(i+1); } } } } if (Character.isUpperCase(c)) { c = Character.toLowerCase(c); } System.out.println(c); 
  • In my opinion, the answer below is correct. Please accept. - Wiktor Stribiżew

1 answer 1

 Pattern p = Pattern.compile("(_[AZ])"); Matcher m = p.matcher("myNew_VarX_VarY_varZ"); StringBuffer sb = new StringBuffer(); while ( m.find() ) { m.appendReplacement(sb, m.group(1).toLowerCase()); } m.appendTail(sb); System.out.println(sb.toString()); // myNew_varX_varY_varZ 
  • Thanks, helped to figure it out! @enzo - Nevada