/** Modifies the current phrase by replacing the nth occurrence of str with repl. * If the nth occurrence does not exist, the current phrase is unchanged. * Precondition: str.length() > 0 and n > 0 */ public void replaceNthOccurrence(String str, int n, String repl) { if(findNthOccurrence(str, n) > 0) { currentPhrase = currentPhrase.substring(0, findNthOccurrence(str, n)) + repl + currentPhrase.substring(findNthOccurrence(str, n) + str.length() + 1); } else { currentPhrase = currentPhrase; } }