private static void subst ( final StringBuilder stringBuilder , final String from , final String to ) { int begin = 0 , end = 0 ; while ( ( end = stringBuilder . indexOf ( from , end ) ) != - 1 ) { stringBuilder . delete ( end , end + from . length ( ) ) ; stringBuilder . insert ( end , to ) ; // update positions begin = end + to . length ( ) ; end = begin ; } }
Substitute sub - strings inside of a string .