Skip to main content
3 of 3
Commonmark migration

PHP, 130 109 bytes

I´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for($s=($a=$argv)[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s,$c,$p+1))$s[$p-1]=$a[3][$k++];echo$k<$i-1?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
prints copy if all characters have been replaced; original else.

Titus
  • 14.8k
  • 1
  • 24
  • 41