I recently wrote a script for character replacement with delayed environment variables, as follows:
@echo off
setlocal enabledelayedexpansion
set /p str=字符串:
set /p old=请输入old:
set /p new=请输入new:
set str=!str:!old!=!new!!
echo !str!
pause
But the result I get is oldnew, not the character replacement result I wanted. If I change the percent signs around old and new to exclamation marks, it works. Why? Wasn't it said that under delayed environment variables, variables have to be enclosed in exclamation marks? And the output result is also quite puzzling.
@echo off
setlocal enabledelayedexpansion
set /p str=字符串:
set /p old=请输入old:
set /p new=请输入new:
set str=!str:!old!=!new!!
echo !str!
pause
But the result I get is oldnew, not the character replacement result I wanted. If I change the percent signs around old and new to exclamation marks, it works. Why? Wasn't it said that under delayed environment variables, variables have to be enclosed in exclamation marks? And the output result is also quite puzzling.

