Code Golf
string sequence add tag
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
# 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).

\def\2#1,#2,#3,{#3#2}\def\1#1,{\def~##1,##2#1{##2\ifnum\numexpr##1=0 \2\fi#1~##1-1,}~}

Output in the PDF:



- saved 2 bytes by changing n to be 0-based.
Answer #2 APL (Dyalog Unicode)
# [APL (Dyalog Unicode)], 15 [bytes]( "When can APL characters be counted as 1 byte each?") ([SBCS]( ".dyalog files using a single byte character set"))

Full program. Prompts for: `s` `n` `u` `t`
[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)]:
[TIO-k89zhyza]: "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.