public static StringBuffer replaceStrStr(final StringBuffer string,final String oldPattern,final String newPattern){
  if ((string == null) || (oldPattern == null) || oldPattern.equals("")|| (newPattern == null)) {
    return string;
  }
  final StringBuffer replaced=new StringBuffer();
  int startIdx=0;
  int idxOld;
  while ((idxOld=string.indexOf(oldPattern,startIdx)) >= 0) {
    replaced.append(string.substring(startIdx,idxOld));
    replaced.append(newPattern);
    startIdx=idxOld + oldPattern.length();
  }
  replaced.append(string.substring(startIdx));
  return replaced;
}

public static StringBuffer replaceStrStr ( final StringBuffer string , final String oldPattern , final String newPattern ) { if ( ( string == null ) || ( oldPattern == null ) || oldPattern . equals ( "" ) || ( newPattern == null ) ) { return string ; } final StringBuffer replaced = new StringBuffer ( ) ; int startIdx = 0 ; int idxOld ; while ( ( idxOld = string . indexOf ( oldPattern , startIdx ) ) >= 0 ) { replaced . append ( string . substring ( startIdx , idxOld ) ) ; replaced . append ( newPattern ) ; startIdx = idxOld + oldPattern . length ( ) ; } replaced . append ( string . substring ( startIdx ) ) ; return replaced ; }
this method replaces in a string one pattern by another one without using regexp .
