static public void substitute ( StringBuilder sbuff , String match , String subst ) { int pos , fromIndex = 0 ; int substLen = subst . length ( ) ; int matchLen = match . length ( ) ; while ( 0 <= ( pos = sbuff . indexOf ( match , fromIndex ) ) ) { sbuff . replace ( pos , pos + matchLen , subst ) ; fromIndex = pos + substLen ; // make sure dont get into an infinite loop } }
Find all occurences of the match in original and substitute the subst string directly into the original .