我有以下for循环:
for /l %%a in (1,1,%count%) do (
<nul set /p=" %%a - "
Echo !var%%a!
)
这将显示如下内容:
1 - REL1206
2 - REL1302
3 - REL1306
我需要创建一个根据迭代次数附加自身的变量。示例变量在 for 循环之后将如下所示:
myVar="1, 2, 3"
我有以下for循环:
for /l %%a in (1,1,%count%) do (
<nul set /p=" %%a - "
Echo !var%%a!
)
这将显示如下内容:
1 - REL1206
2 - REL1302
3 - REL1306
我需要创建一个根据迭代次数附加自身的变量。示例变量在 for 循环之后将如下所示:
myVar="1, 2, 3"
例子:
@ECHO OFF &SETLOCAL
SET /a count=5
for /l %%a in (1,1,%count%) do call set "Myvar=%%Myvar%%, %%a"
ECHO %Myvar:~2%
..输出是:
1, 2, 3, 4, 5
使用延迟扩展
setlocal enableextensions enabledelayedexpansion
SET OUTPUTSTRING=
for /l %%a in (1,1,%count%) do (
<nul set /p=" %%a - "
Echo !var%%a!
if .!OUTPUTSTRING!==. (
SET OUTPUTSTRING=%%a
) ELSE (
SET OUTPUTSTRING=!OUTPUTSTRING!, %%a
)
)
SET OUTPUTSTRING