Substring Substitution

Challenge

Implement a program that given three strings a, b, and c, substitutes all instances of the substring b in a with c.

In other words, implement Ruby's String#gsub with strings instead of regexes (a.gsub b, c).

Rules

• Standard loopholes apply.
• You may not use a builtin that performs this exact task.
• This is , shortest answer wins.

Not a duplicate of this challenge.

Test case

sub("test 1 test 1 test 1", "1", "what")
--> "test what test what test what"

• This has all the typical problems of do X without Y challenges. Are splitting/joining built-ins allowed? If so, this is trivial and there's really no reason to ban sibstitution built-ins. If not, what is allowed? – Dennis Nov 20 '16 at 2:57
• @wat You answered yes for Dennis's question about using string split/join, then said in question that they are not allowed. So they are allowed and not allowed at the same time? – Link Ng Nov 20 '16 at 3:18
• By "join or split strings" do you mean "join or split anything"? As an example Jelly 5 bytes œṣµj⁵ does not split any strings since Jelly has no strings. – Jonathan Allan Nov 20 '16 at 3:19
• Modifying the challenge to fit Jelly will just result in another language being pointed out that doesn't fit the wording. It's easiest just not to ban built ins. – trichoplax Nov 20 '16 at 3:25
• @wat - lists, numbers (decimals, reals, complex) and characters. The above is achieved with a list of characters. – Jonathan Allan Nov 20 '16 at 4:02

JavaScript (ES6), 27 bytes

(a,b,c)=>a.split(b).join(c)


Jelly, 4 bytes

œṣj⁵


Try it online!

How it works

œṣj⁵  Main link. Arguments: x, y, z (strings)

œṣ    Split x around occurrences of y.
j⁵  Join the resulting string array with separator z.


import Data.Lists

Argument order is c b a. Usage example: ( (.splitOn).(.).intercalate ) "ww" "ee" "aeedwwfeegeh" -> "awwdwwfwwgeh".
Just some library functions to split the input string at every b and rejoin the parts with c in-between.