public static String replace(String source,String target,String replacement){
  StringBuffer output=new StringBuffer();
  int n=0;
  while (true) {
    int off=source.indexOf(target,n);
    if (off == -1) {
      output.append(source.substring(n));
      break;
    }
    output.append(source.substring(n,off));
    output.append(replacement);
    n=off + target.length();
  }
  return output.toString();
}

public static String replace ( String source , String target , String replacement ) { StringBuffer output = new StringBuffer ( ) ; int n = 0 ; while ( true ) { int off = source . indexOf ( target , n ) ; if ( off == - 1 ) { output . append ( source . substring ( n ) ) ; break ; } output . append ( source . substring ( n , off ) ) ; output . append ( replacement ) ; n = off + target . length ( ) ; } return output . toString ( ) ; }
description of the method
