or
Code Golf string sequence
Adám
From a `[A-Za-z]` string `s`, replace `n`th 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'`
Top Answer
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.
Answer #2
Adám
# [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:

 `⎕` prompt for number `n`

 `-` negate it (meaning "only the Nth" rather than "the first N")

`⍞` prompt for string `u`

…`⎕R` replace the following with that:

 `⍞` 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
Skillmon replying to Adám
I thought the call would be counted as well, my misconception.
Adám replying to Skillmon
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.
Skillmon replying to Adám
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).
Adám replying to Skillmon
Yes.
Adám replying to Skillmon
You can choose 0-based or 1-based indexing.
Adám replying to Skillmon
I don't know what that means.
Skillmon replying to Adám
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?)
Skillmon replying to Adám
and (just to make sure) `n` can't start at 0?
Skillmon replying to Adám
input delimiters will be counted as additional tokens then, iirc?
Adám replying to Skillmon
No, you can take input by any means, as per default i/o rules.
Skillmon
@Adám Is the order of the arguments fixed?
Adám replying to xnor
Clarified.
xnor
@Adám How are overlapping substrings counted? For example, `aba` in `ababa`.
Adám replying to Bubbler
Updated.
Bubbler
@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 `n`th 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?