China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-06 06:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Who can explain the meaning of the code by moderator 3742668? View 2,406 Replies 8
Original Poster Posted 2007-09-02 19:44 ·  中国 山西 太原 联通
中级用户
★★
Credits 216
Posts 81
Joined 2007-08-06 12:23
18-year member
UID 94721
Gender Male
Status Offline
@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
Crossings must be my teacher
Modest progress can be
Floor 2 Posted 2007-09-02 20:32 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
19-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
If there is "感谢您" in 1.txt, replace it with "谢谢您". Is that correct
Floor 3 Posted 2007-09-02 20:49 ·  中国 山西 太原 联通
中级用户
★★
Credits 216
Posts 81
Joined 2007-08-06 12:23
18-year member
UID 94721
Gender Male
Status Offline
No translation needed as the content is already in English.
Crossings must be my teacher
Modest progress can be
Floor 4 Posted 2007-09-02 21:00 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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.
Floor 5 Posted 2007-09-02 21:34 ·  中国 山西 太原 联通
中级用户
★★
Credits 216
Posts 81
Joined 2007-08-06 12:23
18-year member
UID 94721
Gender Male
Status Offline
Um, I know what you're talking about. I just want to know what %2 and %3 represent in this code?
Crossings must be my teacher
Modest progress can be
Floor 6 Posted 2007-09-03 07:16 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
19-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
If you don't understand, just create a text and take a look? Don't ask without thinking
Floor 7 Posted 2007-09-03 09:38 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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 ...)
Floor 8 Posted 2007-09-03 18:32 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 9 Posted 2007-10-23 14:21 ·  中国 浙江 温州 电信
初级用户
★★
Credits 158
Posts 89
Joined 2007-04-25 08:06
19-year member
UID 86402
Gender Male
Status Offline
Forum Jump: