code: public static String replace(String text, String oldString, String newString)
     {
        if (text == null || oldString == null || newString == null)
        {
           throw new IllegalArgumentException("null argument");
        }
        int pos = text.indexOf(oldString);
        if (pos == -1)
        {
           return text;
        }
        int lastPos = 0;
        StringBuilder sb = new StringBuilder(text.length());
        while (pos != -1)
        {
           sb.append(text.substring(lastPos, pos));
           sb.append(newString);
           lastPos = pos + oldString.length();
           pos = text.indexOf(oldString, lastPos);
        }
        if (lastPos < text.length())
        {
           sb.append(text.substring(lastPos));
        }
        return sb.toString();
     }
docs: Replaces all occurences of <code>oldString</code> in <code>text</code> with
  <code>newString</code>.
  
  @param text
  @param oldString
  old substring to be replaced with <code>newString</code>
  @param newString
  new substring to replace occurences of <code>oldString</code>
  @return a string