中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 03:20
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Question about character replacement with delayed environment variables
Printable Version  857 / 2
Floor1 lionlove Posted 2010-08-15 11:18
新手上路 Posts 4 Credits 5
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.
Floor2 HAT Posted 2010-08-15 13:11
版主 Posts 5,017 Credits 9,023
Variable nesting isn't used like this, refer to:
http://bbs.bathome.net/thread-2899-1-1.html
Floor3 lionlove Posted 2010-08-15 15:21
新手上路 Posts 4 Credits 5
After reading the reference materials, I understand a little. Could the moderator explain how variable nesting is used, and what needs attention when using variable nesting? Thanks.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023