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