SET Obj_Length=2
SET Obj[0].Name=Test1
SET Obj[0].Value=Hello World
SET Obj[1].Name=Test2
SET Obj[1].Value=blahblah
這樣就定義了一個數(shù)組了,而且是結(jié)構(gòu)體的數(shù)組。
在需要取值的時候,可以這么玩:
SET Obj_Index=0
:LoopStart
IF %Obj_Index% EQU %Obj_Length% GOTO :EOF
SET Obj_Current.Name=0
SET Obj_Current.Value=0
FOR /F "usebackq delims==. tokens=1-3" %%I IN (`SET Obj[%Obj_Index%]`) DO (
SET Obj_Current.%%J=%%K
)
ECHO Name = %Obj_Current.Name%
ECHO Value = %Obj_Current.Value%
ECHO.
SET /A Obj_Index=%Obj_Index% + 1
GOTO LoopStart
輸出結(jié)果:
Name = Test1
Value = Hello World
Name = Test2
Value = blahblah