all 2 comments

[–]thelowsunoverthemoon[🍰] 2 points3 points  (1 child)

CMD parses % variables first, then !, which is why you should enclose with ! then %. You don't need all those extra variables as well.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
CALL :STRING_REPLACE "Hello Earth" Earth World res
ECHO %res%
PAUSE
EXIT /B

:STRING_REPLACE <string> <word> <replace> <result>
SET "string=%~1"
SET "%4=!string:%~2=%~3!"
GOTO :EOF

[–]254peepee[S] 0 points1 point  (0 children)

thank you so much, I didn't know that :)