Take the string abcdfghjk
. To overwrite it, starting from f
, with the string wxyz
, you would continue along the original, replacing each character with the one from the replacement string. The result would be abcdwxyzk
.
Now, consider a string which would be too long to fit, like lmnopqrs
. Starting at f
you would get abcdlmnop
, then hit the end of the string. In order to continue, you wrap back to the beginning, resulting in qrsdefghi
. With a long enough string, you could even wrap around multiple times.
Task:
You should take three inputs: the original string, the replacement string, and an index to start replacing at. This can be zero or one indexed.
Test Cases:
"This is a string" "That" 0 -> "That is a string"
"This is a string" "That" 5 -> "This That string"
"This is a string" "That" 14 -> "atis is a striTh"
"hi" "Hello there!" 0 -> "e!"
"hi" "Hello there!" 1 -> "!e"
"over" "write multiple times" 0 -> "imes"
"over" "write multiple times" 3 -> "mesi"
Other:
This is code-golf, shortest answer per language in bytes wins!