static public String substitute ( String original , String [ ] match , String [ ] subst ) { boolean ok = true ; for ( String aMatch : match ) { if ( original . contains ( aMatch ) ) { ok = false ; break ; } } if ( ok ) { return original ; } // gotta do it; StringBuilder sb = new StringBuilder ( original ) ; for ( int i = 0 ; i < match . length ; i ++ ) { substitute ( sb , match [ i ] , subst [ i ] ) ; } return sb . toString ( ) ; }
Find all occurences of match strings in original and substitute the corresponding subst string .