Code Golf
string sequence add tag
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 TeX
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 APL (Dyalog Unicode)
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"

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.