标题: 关于 For 问题
[打印本页]
作者: jhg1975
时间: 2010-10-4 09:29
标题: 关于 For 问题
下面代码作用是从 1.txt 中读取内容,组合成字符串 ="http://dict.cn/ws.php?q=%w%"
------------------------------------------------------------------------------------------------
1.TXT 内容
china
apple
list
循环后字符串
"http://dict.cn/ws.php?q=china"
"http://dict.cn/ws.php?q=apple"
"http://dict.cn/ws.php?q=list"
问题是运行下面代码后,一直Echo 不出 %url% 中希望内容?
code:
@echo off
setlocal enabledelayedexpansion
set "command1=wget -q -O - "
for /f "delims=" %%w in (1.txt) do (
set url="http://dict.cn/ws.php?q=%w%"
echo %%w
echo %url%
)
)
作者: lovelymorning
时间: 2010-10-4 12:27
@echo off
for /f "delims=" %%a in (1.txt) do (
set "url=http://dict.cn/ws.php?q=%%a"
call echo %%url%%
)
pause
exit
作者: zhoupeng243
时间: 2010-10-4 14:36
2楼用call可以
方法2:
楼主既然有setlocal enabledelayedexpansion这句
把echo %url%修改为 echo !url!就好了
作者: paladinjin
时间: 2010-10-6 22:26
call?似乎除了调用别的程序还有什么?call echo?
作者: photonjl
时间: 2010-10-6 22:44
@echo off
setlocal enabledelayedexpansion
set "command1=wget -q -O - "
for /f "delims=" %%w in (1.txt) do (
set url="http://dict.cn/ws.php?q=%%w"
echo %%w
echo !url!
)
)