public static String replaceAll(String source,String pattern,String replace){
  StringBuilder sb=new StringBuilder();
  int idx=0;
  String workingSource=source;
  idx=workingSource.indexOf(pattern);
  if (idx == -1) {
    return source;
  }
  while (idx != -1) {
    sb.append(workingSource.substring(0,idx));
    sb.append(replace);
    workingSource=workingSource.substring(idx + pattern.length());
    idx=workingSource.indexOf(pattern);
  }
  sb.append(workingSource);
  return sb.toString();
}

public static String replaceAll ( String source , String pattern , String replace ) { StringBuilder sb = new StringBuilder ( ) ; int idx = 0 ; String workingSource = source ; idx = workingSource . indexOf ( pattern ) ; if ( idx == - 1 ) { return source ; } while ( idx != - 1 ) { sb . append ( workingSource . substring ( 0 , idx ) ) ; sb . append ( replace ) ; workingSource = workingSource . substring ( idx + pattern . length ( ) ) ; idx = workingSource . indexOf ( pattern ) ; } sb . append ( workingSource ) ; return sb . toString ( ) ; }
this method replaces all occurrences of the pattern with the replacement string
