private static String replace(final String inString,final String oldPattern,final String newPattern){
  if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
    return inString;
  }
  final StringBuffer sbuf=new StringBuffer();
  int pos=0;
  int index=inString.indexOf(oldPattern);
  final int patLen=oldPattern.length();
  while (index >= 0) {
    sbuf.append(inString.substring(pos,index));
    sbuf.append(newPattern);
    pos=index + patLen;
    index=inString.indexOf(oldPattern,pos);
  }
  sbuf.append(inString.substring(pos));
  return sbuf.toString();
}

private static String replace ( final String inString , final String oldPattern , final String newPattern ) { if ( ! hasLength ( inString ) || ! hasLength ( oldPattern ) || newPattern == null ) { return inString ; } final StringBuffer sbuf = new StringBuffer ( ) ; int pos = 0 ; int index = inString . indexOf ( oldPattern ) ; final int patLen = oldPattern . length ( ) ; while ( index >= 0 ) { sbuf . append ( inString . substring ( pos , index ) ) ; sbuf . append ( newPattern ) ; pos = index + patLen ; index = inString . indexOf ( oldPattern , pos ) ; } sbuf . append ( inString . substring ( pos ) ) ; return sbuf . toString ( ) ; }
replace all occurrences of a substring within a string with another string .
