Board logo

标题: [求助]DOS数组? [打印本页]

作者: sinbao     时间: 2007-12-28 12:08    标题: [求助]DOS数组?

如下,array是一个类似数组的变量,以逗号分隔,目的是打印这个数组.请教一下有没有别的更好的方法?或者该代码有值得改进的地方?
@echo off
set array=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u
for /f "tokens=1-26 delims=," %%a in ("%array%") do (
        if not "%%a"=="" echo %%a
        if not "%%b"=="" echo %%b
        if not "%%c"=="" echo %%c
        if not "%%d"=="" echo %%d
        if not "%%e"=="" echo %%e
        if not "%%f"=="" echo %%f
        if not "%%g"=="" echo %%g
        if not "%%h"=="" echo %%h
        if not "%%i"=="" echo %%i
        if not "%%j"=="" echo %%j
        if not "%%k"=="" echo %%k
        if not "%%l"=="" echo %%l
        if not "%%m"=="" echo %%m
        if not "%%n"=="" echo %%n
        if not "%%o"=="" echo %%o
        if not "%%p"=="" echo %%p
        if not "%%q"=="" echo %%q
        if not "%%r"=="" echo %%r
        if not "%%s"=="" echo %%s
        if not "%%t"=="" echo %%t
        if not "%%u"=="" echo %%u
        if not "%%v"=="" echo %%v
        if not "%%w"=="" echo %%w
        if not "%%x"=="" echo %%x
        if not "%%y"=="" echo %%y
        if not "%%z"=="" echo %%z
)
[ Last edited by sinbao on 2007-12-28 at 12:09 PM ]
作者: wjcing     时间: 2007-12-28 13:45
%%a

不就是for传的变量吗?
为什么还要
        if not "%%b"=="" echo %%b
        if not "%%c"=="" echo %%c
        if not "%%d"=="" echo %%d
        if not "%%e"=="" echo %%e
        if not "%%f"=="" echo %%f
        if not "%%g"=="" echo %%g
        if not "%%h"=="" echo %%h
        if not "%%i"=="" echo %%i
        if not "%%j"=="" echo %%j
        if not "%%k"=="" echo %%k
        if not "%%l"=="" echo %%l
        if not "%%m"=="" echo %%m
        if not "%%n"=="" echo %%n
        if not "%%o"=="" echo %%o
        if not "%%p"=="" echo %%p
        if not "%%q"=="" echo %%q
        if not "%%r"=="" echo %%r
        if not "%%s"=="" echo %%s
        if not "%%t"=="" echo %%t
        if not "%%u"=="" echo %%u
        if not "%%v"=="" echo %%v
        if not "%%w"=="" echo %%w
        if not "%%x"=="" echo %%x
        if not "%%y"=="" echo %%y
        if not "%%z"=="" echo %%z
这些判断呢??有这些变量吗??
作者: Climbing     时间: 2007-12-28 15:41

@echo off
set array=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u
for %%i in (%array%) do echo %%i

作者: sinbao     时间: 2008-1-4 10:34


  Quote:
Originally posted by Climbing at 2007-12-28 03:41 PM:
@echo off
set array=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u
for %%i in (%array%) do echo %%i

!
作者: fastslz     时间: 2008-1-4 11:34
没明白楼主意图
@echo off
call :xxx a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u
pause
exit

:xxx
if "%1"=="" goto:eof
echo %1
shift
goto xxx

作者: sinbao     时间: 2008-1-4 13:51
对不起,给错分了,应该给Climbing的给了wjcing...
现在补上了.

@fastslz:
我的意思是Climbing的解答很好!
你的解答也很酷!
明天再给你补分.

[ Last edited by sinbao on 2008-1-4 at 01:53 PM ]