code: public static String replaceSubstring(String inString, String subString,
  					String replaceString) {
  
      StringBuffer result = new StringBuffer();
      int oldLoc = 0, loc = 0;
      while ((loc = inString.indexOf(subString, oldLoc))!= -1) {
        result.append(inString.substring(oldLoc, loc));
        result.append(replaceString);
        oldLoc = loc + subString.length();
      }
      result.append(inString.substring(oldLoc));
      return result.toString();
    }
docs: Replaces with a new string, all occurrences of a string from
  another string.
  
  @param inString the string to replace substrings in.
  @param subString the substring to replace.
  @param replaceString the replacement substring
  @return the input string with occurrences of substring replaced.