pass through the string searching for the n occurence. once you found it, remeber the index of the first letter of the pattern (in the string).

pass again through the string and replace the pattern with your text (begining with the caracter at the index position).