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-06-24 06:49
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask: Batch processing for judging file content and character replacement View 4,211 Replies 16
Floor 16 Posted 2006-10-31 03:46 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
rem Read the ping command return result using for;
for /f "delims=" %%i in ('ping www.21cn.com') do (

rem Initialize ret (here it means clearing);
set ret=

rem "if defined %%a" is to check whether the corresponding variable %%a exists, and if it exists, replace it with the variable value; (the variable is the word we want to translate, and the variable value has been set to the corresponding Chinese meaning)
for %%a in (%%i) do if defined %%a (set ret=!ret!!%%a!) else set ret=!ret! %%a

rem Because the time is not easy to translate here, so directly adopt this alternative method.
if not "!ret!"=="" (set ret=!ret:time=时间! && echo !ret!) else echo.
)
Floor 17 Posted 2006-10-31 06:27 ·  中国 广东 茂名 电信
中级用户
★★
Credits 261
Posts 123
Joined 2006-06-06 19:23
20-year member
UID 56648
Status Offline
These two sentences are still not understood. Can you explain again?
if defined %%a (set ret=!ret!!%%a!) else set ret=!ret! %%a
if not "!ret!"=="" (set ret=!ret:time=时间! && echo !ret!) else echo.
Can it be replaced in the whole section? For example
set Request timed out.=Response request timed out.
set TTL Expired in Transit=The number of required hops exceeded the "Time to Live" (TTL)
set Approximate round trip times in milli-seconds:=Approximate round trip times in milliseconds:=
This seems to work in the command line, but it doesn't seem to work in this batch processing. Is the variable name with spaces not okay? Can the variable value have spaces? If it can, can we first set a variable to be in English? For example
set imedout=Request timed out.
set imedout=Response request timed out.
Because I haven't understood it yet, I can't test it by myself. Please take a look again.

[ Last edited by yangzhiyi on 2006-11-1 at 01:56 AM ]
Forum Jump: