code: public static String subst(final StringBuffer buff, final String from,
              final String to, final String string)
     {
        int begin = 0, end = 0;
  
        while ((end = string.indexOf(from, end)) != -1)
        {
           // append the first part of the string
           buff.append(string.substring(begin, end));
  
           // append the replaced string
           buff.append(to);
  
           // update positions
           begin = end + from.length();
           end = begin;
        }
  
        // append the rest of the string
        buff.append(string.substring(begin, string.length()));
  
        return buff.toString();
     }
docs: Substitute sub-strings in side of a string.
  
  @param buff Stirng buffer to use for substitution (buffer is not reset)
  @param from String to substitute from
  @param to String to substitute to
  @param string String to look for from in
  @return Substituted string