code: public static String replace(String pSource, String pPattern, String pReplace) {
          if (pPattern.length() == 0) {
              return pSource;// Special case: No pattern to replace
          }
  
          int match;
          int offset = 0;
          StringBuilder result = new StringBuilder();
  
          // Loop string, until last occurence of pattern, and replace
          while ((match = pSource.indexOf(pPattern, offset)) != -1) {
              // Append everything until pattern
              result.append(pSource.substring(offset, match));
              // Append the replace string
              result.append(pReplace);
              offset = match + pPattern.length();
          }
  
          // Append rest of string and return
          result.append(pSource.substring(offset));
  
          return result.toString();
      }
docs: Replaces a substring of a string with another string. All matches are
  replaced.
  
  @param pSource  The source String
  @param pPattern The pattern to replace
  @param pReplace The new String to be inserted instead of the
  replace String
  @return The new String with the pattern replaced