cdm/src/main/java/ucar/unidata/util/StringUtil2.java
static public String replace(String x, char[] replaceChar, String[] replaceWith) {
    // common case no replacement
    boolean ok = true;
    for (char aReplaceChar : replaceChar) {
      int pos = x.indexOf(aReplaceChar);
      ok = (pos < 0);
      if (!ok)
        break;
    }
    if (ok)
      return x;

    // gotta do it
    StringBuilder sb = new StringBuilder(x);
    for (int i = 0; i < replaceChar.length; i++) {
      int pos = x.indexOf(replaceChar[i]);
      if (pos >= 0) {
        replace(sb, replaceChar[i], replaceWith[i]);
      }
    }

    return sb.toString();
  }
static public String replace(String x, char[] replaceChar, String[] replaceWith) {
    // common case no replacement
    boolean ok = true;
    for (char aReplaceChar : replaceChar) {
      int pos = x.indexOf(aReplaceChar);
      ok = (pos < 0);
      if (!ok)
        break;
    }
    if (ok)
      return x;

    // gotta do it
    StringBuilder sb = new StringBuilder(x);
    for (int i = 0; i < replaceChar.length; i++) {
      int pos = x.indexOf(replaceChar[i]);
      if (pos >= 0) {
        replace(sb, replaceChar[i], replaceWith[i]);
      }
    }

    return sb.toString();
  }
static public String replace ( String x , char [ ] replaceChar , String [ ] replaceWith ) { // common case no replacement
 boolean ok = true ; for ( char aReplaceChar : replaceChar ) { int pos = x . indexOf ( aReplaceChar ) ; ok = ( pos < 0 ) ; if ( ! ok ) break ; } if ( ok ) return x ; // gotta do it
 StringBuilder sb = new StringBuilder ( x ) ; for ( int i = 0 ; i < replaceChar . length ; i ++ ) { int pos = x . indexOf ( replaceChar [ i ] ) ; if ( pos >= 0 ) { replace ( sb , replaceChar [ i ] , replaceWith [ i ] ) ; } } return sb . toString ( ) ; }
Replace all occurrences of any char in replaceChar with corresponding String in replaceWith

@param x           operate on this string
@param replaceChar get rid of these
@param replaceWith replace with these
@return resulting string
Replace all occurrences of any char in replaceChar with corresponding String in replaceWith