public static final String replace(String replaceIn,String toReplace,String replaceWith){
  StringBuffer buf=new StringBuffer(replaceIn);
  int replaceLength=toReplace.length();
  int replaceWithLength=replaceWith.length();
  int netLength=replaceWithLength - replaceLength;
  int index=-1;
  int count=0;
  while ((index=replaceIn.indexOf(toReplace,index + 1)) != -1) {
    int bufIndex=index + (count * netLength);
    buf.replace(bufIndex,bufIndex + replaceLength,replaceWith);
    count++;
  }
  return buf.toString();
}

public static final String replace ( String replaceIn , String toReplace , String replaceWith ) { StringBuffer buf = new StringBuffer ( replaceIn ) ; int replaceLength = toReplace . length ( ) ; int replaceWithLength = replaceWith . length ( ) ; int netLength = replaceWithLength - replaceLength ; int index = - 1 ; int count = 0 ; while ( ( index = replaceIn . indexOf ( toReplace , index + 1 ) ) != - 1 ) { int bufIndex = index + ( count * netLength ) ; buf . replace ( bufIndex , bufIndex + replaceLength , replaceWith ) ; count ++ ; } return buf . toString ( ) ; }
replace substrings of a string .
