public static String replace(String s, String replace, String with) {

        if (s == null || replace == null) {
            return s;
        }

        if (with == null) {
            with = "";
        }

        StringBuffer b          = new StringBuffer();
        int          start      = 0;
        int          lenreplace = replace.length();

        while (true) {
            int i = s.indexOf(replace, start);

            if (i == -1) {
                b.append(s.substring(start));

                break;
            }

            b.append(s.substring(start, i));
            b.append(with);

            start = i + lenreplace;
        }

        return b.toString();
    }
public static String replace ( String s , String replace , String with ) { if ( s == null || replace == null ) { return s ; } if ( with == null ) { with = "" ; } StringBuffer b = new StringBuffer ( ) ; int start = 0 ; int lenreplace = replace . length ( ) ; while ( true ) { int i = s . indexOf ( replace , start ) ; if ( i == - 1 ) { b . append ( s . substring ( start ) ) ; break ; } b . append ( s . substring ( start , i ) ) ; b . append ( with ) ; start = i + lenreplace ; } return b . toString ( ) ; }
Replaces all occurrences of <code>replace</code> in <code>s</code>
with the <code>String</code> object: <code>with</code>
@param s the target for replacement
@param replace the substring(s), if any, in <code>s</code> to replace
@param with the value to substitute for <code>replace</code>
@return <code>s</code>, with all occurences of <code>replace</code>
replaced by <code>with</code>