我想实现以下功能
比如有1.txt,内容如下(abc是任意长度的不含空格的字符)
a
b
c
我想从这个文本文件中提取a赋值到变量 x ,提取b赋值到变量 y ,提取 c 赋值到变量 z
请问DX怎样实现?
[ Last edited by nerfg002 on 2009-11-2 at 14:47 ]作者: chenall 时间: 2009-11-1 00:37 随便写了一下,楼主可以试下。
for /f %%i in (1.txt) do call :赋值 %%i
goto :eof
:赋值
if not defined x (set x=%1 && goto :eof)
if not defined y (set y=%1 && goto :eof)
if not defined z (set z=%1 && goto :eof)作者: nerfg002 时间: 2009-11-1 11:09 楼上的代码测试不行,能在改下么作者: balinger 时间: 2009-11-1 16:47 @echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set k=0
for /f "delims=" %%a in (1.txt) do (
set /a k+=1
if !k!==1 set x=%%a
if !k!==2 set y=%%a
if !k!==3 set z=%%a
)
echo x=%x% y=%y% z=%z%