static public String substitute ( String original , String match , String subst ) { String s = original ; int pos ; while ( 0 <= ( pos = s . indexOf ( match ) ) ) { StringBuilder sb = new StringBuilder ( s ) ; s = sb . replace ( pos , pos + match . length ( ) , subst ) . toString ( ) ; } return s ; }
Find all occurrences of the match in original and substitute the subst string .