There are two common ways (and some unusual ones).
Use double call extension.
SET search=foo SET repl=bar SET blah=double-foo CALL SET blah=%%blah:%search%=%repl%%%
In the first βscanβ, it expands to CALL SET blah=%blah:foo=bar% , and the call increases the time in seconds to the desired result.
The second way is a delayed option.
SETLOCAL EnableDelayedExpansion SET search=foo SET repl=bar SET blah=double-foo SET blah=!blah:%search%=%repl%!
This works because slow expansion is performed after the percentage increase.
I would prefer a delayed option because it is faster and safer against special characters.
The FOR-Loop-Variable option is an unusual way; it also works with special characters in search / replace variables.
SETLOCAL EnableDelayedExpansion SET "search=foo>" SET "repl=bar & bar" SET "blah=double-foo> &|<>" for %%s in ("!search!") do ( for %%r in ("!repl!") do ( SET "blah=!blah:%%~s=%%~r!" ) )
jeb
source share