or
Code Golf string sequence
From a [A-Za-z] string s, replace nth occurrence (guaranteed to occur) of substring t with another string u of identical length. Every character in s can only form part of one t. E.g. 'aba' occurs only twice in 'abababa'.

### Example

s='aABCbABCdefABCc', n=2, t='ABC', u='DEF' -> 'aABCbDEFdefABCc'
Skillmon
# TeX, 86 bytes

The definition of the function is 86 bytes long and we need one byte per argument as a delimiter (I used a comma). The function's name is 2 bytes long, so calling it costs another 2 bytes, totalling 94 bytes plus the arguments.

An entire script defining the function (1st line) and applying it to the example arguments (2nd line). The \bye is included to end the pdftex interpreter (the output file is only written at the end).

tex
\def\2#1,#2,#3,{#3#2}\def\1#1,{\def~##1,##2#1{##2\ifnum\numexpr##1=0 \2\fi#1~##1-1,}~}
\1ABC,1,aABCbABCdefABCc,DEF,\bye


Output in the PDF:


aABCbDEFdefABC


**EDIT**

- saved 2 bytes by changing n to be 0-based.
# [APL (Dyalog Unicode)], 15 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?") ([SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set"))

Full program. Prompts for: s n u t
apl
⍞⎕R⍞⍠'ML'(-⎕)⊢⍞

[Try it online!][TIO-k89zhyza]

⍞ prompt for string s

⊢ on that…

⍠'ML'(…) set the Match Limit to:

&emsp;⎕ prompt for number n

&emsp;- negate it (meaning "only the Nth" rather than "the first N")

⍞ prompt for string u

…⎕R replace the following with that:

&emsp;⍞ prompt for string t

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-k89zhyza]: https://tio.run/##SyzI0U2pTMzJT///qKO94P@j3nmP@qYGgajeBeq@PuoaukC@5qOuRUAhkJL/CmBQwJXo6OScBMQpqWlAMpnLiMvF1Y0LyAQA "APL (Dyalog Unicode) – Try It Online"
Replace Nth occurrence of substring
I thought the call would be counted as well, my misconception.
The call isn't counted at all, only the code to define the function. However, if the syntax for defining the function requires listing the arguments with commas, then yes, those commas count.
well, for example a function in C will take its arguments enclosed in parenthesis and separated by commas, so this adds 1+n bytes for its call (n being the number of arguments).
Yes.
You can choose 0-based or 1-based indexing.
I don't know what that means.
and is returning in an unclean state legal (e.g., is it ok if the interpreter/compiler will throw errors if the output is correct?)
and (just to make sure) n can't start at 0?
input delimiters will be counted as additional tokens then, iirc?
No, you can take input by any means, as per default i/o rules.
@Adám Is the order of the arguments fixed?
Clarified.
@Adám How are overlapping substrings counted? For example, aba in ababa.
Updated.
@Adám 1) Is it guaranteed that length(t)=length(u)? 2) Can we choose between 1-indexing and 0-indexing for n? 3) Can we assume there will always be nth occurrence? 4) What is the alphabet of s, t, and u? Will they contain only [A-Za-z] (upper- and lowercase alphabets), or something else?