code: public static String mergeToSingleUnderscore(String s) {
          StringBuffer buffer = new StringBuffer();
          boolean inMerge = false;
          for (int i = 0; i < s.length(); i++) {
              char c = s.charAt(i);
              if (c == ' ' || c == '_') {
                  if (!inMerge) {
                      buffer.append('_');
                  }
                  inMerge = true;
  
              } else {
                  inMerge = false;
                  buffer.append(c);
              }
          }
  
          return buffer.toString();
      }
docs: Merge all consecutive underscores and spaces into a single underscore, e.g. "ab___c_  _d" becomes "ab_c_d"
  
  @param s String to process
  @return The resulting string.