code: public static String replace(String input, String find, String repl, boolean firstOnly, boolean ignoreCase) {
  
  	int findLen = find.length();
  
  	if (findLen == 0) return input;
  
  	// String scan = input;
  
  	/*
  	 * if ( ignoreCase ) { scan = scan.toLowerCase(); find = find.toLowerCase(); } else
  	 */ if (!ignoreCase && findLen == repl.length()) {
  
  	    if (find.equals(repl)) return input;
  	    if (!firstOnly && findLen == 1) return input.replace(find.charAt(0), repl.charAt(0));
  	}
  
  	/*
  	 * print.e(input); print.e(input.length());
  	 * 
  	 * print.e(scan); print.e(scan.length());
  	 */
  
  	/*
  	 * for(int i=0;i<scan.length();i++) { print.e(scan.charAt(i)); }
  	 */
  
  	int pos = ignoreCase ? indexOfIgnoreCase(input, find) : input.indexOf(find);
  
  	if (pos == -1) return input;
  
  	int start = 0;
  	StringBuilder sb = new StringBuilder(repl.length() > find.length() ? (int) Math.ceil(input.length() * 1.2) : input.length());
  
  	while (pos != -1) {
  
  	    sb.append(input.substring(start, pos));
  	    sb.append(repl);
  
  	    start = pos + findLen;
  
  	    if (firstOnly) break;
  
  	    pos = ignoreCase ? indexOfIgnoreCase(input, find, start) : input.indexOf(find, start);
  	}
  
  	if (input.length() > start) sb.append(input.substring(start));
  
  	return sb.toString();
      }
docs: performs a replace operation on a string
  
  @param input - the string input to work on
  @param find - the substring to find
  @param repl - the substring to replace the matches with
  @param firstOnly - if true then only the first occurrence of {@code find} will be replaced
  @param ignoreCase - if true then matches will not be case sensitive
  @return