中国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-06 07:12
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Help] Who can explain the meaning of the code by moderator 3742668?
Printable Version  2,407 / 8
Floor1 icyheart Posted 2007-09-02 19:44
中级用户 Posts 81 Credits 216
@echo off

echo Remove quotes:
call :replace 1.txt "

echo.
echo Replace characters:
call :replace 1.txt "Thank you" "Thank you"

pause>nul
goto :eof

:replace
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1* delims=" %%i in (%1) do set var=%%i & echo !var:%2=%3!
endlocal
goto :eof

This is the code of moderator 3742668. Can anyone explain it? Especially this line var:%2=%3
Thank you
Floor2 junchen2 Posted 2007-09-02 20:32
高级用户 Posts 219 Credits 537 From 杭州--半山
If there is "感谢您" in 1.txt, replace it with "谢谢您". Is that correct
Floor3 icyheart Posted 2007-09-02 20:49
中级用户 Posts 81 Credits 216
No translation needed as the content is already in English.
Floor4 slore Posted 2007-09-02 21:00
铂金会员 Posts 2,478 Credits 5,212
Take a look at the help...

If you don't understand, use echo to see what it actually executes...



The environment variable substitution has been enhanced as follows:

%PATH:str1=str2%

This will expand the PATH environment variable, replacing each "str1" in the expanded result with "str2".
To effectively remove all "str1" from the expanded result, "str2" can be empty.
"str1" can start with an asterisk; in this case, "str1" will match from the start of the expanded result to the first occurrence of the remaining part of str1.

Substrings can also be specified for file extensions.
Floor5 icyheart Posted 2007-09-02 21:34
中级用户 Posts 81 Credits 216
Um, I know what you're talking about. I just want to know what %2 and %3 represent in this code?
Floor6 junchen2 Posted 2007-09-03 07:16
高级用户 Posts 219 Credits 537 From 杭州--半山
If you don't understand, just create a text and take a look? Don't ask without thinking
Floor7 slore Posted 2007-09-03 09:38
铂金会员 Posts 2,478 Credits 5,212
Still look at the help...

If command extensions are enabled, CALL will change as follows:

The CALL command now accepts labels as the target of CALL. The syntax is:

CALL:label arguments

A new batch file context is created with the specified arguments, and control is passed to the statement after the label is specified. You must "exit" twice by reaching the end of the batch script file twice. The first time you reach the end of the file, control returns to immediately after the CALL statement. The second time will exit the batch script. Type GOTO /? to see the description of the GOTO : EOF extension, which allows you to return from a batch script.

In addition, the batch script text parameter references (%0, %1, etc.) have changed as follows:


%* in the batch script indicates all arguments (such as %1 %2 %3 %4 %5 ...)
Floor8 不得不爱 Posted 2007-09-03 18:32
超级版主 Posts 2,044 Credits 5,310 From 四川南充
call :replace 1.txt "Thank you" "Thank you"
↑ ↑ ↑ ↑
line number %1 %2 %3
Floor9 kgdetg1127 Posted 2007-10-23 14:21
初级用户 Posts 89 Credits 158
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023