我正在尝试让这个程序使用不同字符串列表中的数字来获取其中一个数组元素的第一个字母。但是,它什么都没有返回。
@echo off
setlocal enableDelayedExpansion
set s=1234 1243 1324 1342 1432 1423 2134 2143 2314 2341 2431 2413 3214 3241 3124 3142 3412 3421 4231 4213 4321 4312 4132 4123
set num[1]=123
set num[2]=456
set num[3]=789
set num[4]=101
for %%a in (!s!) do (
set w=%%a
echo !w!
set fnum=!num[%w:~0,1%]!
echo !fnum!
)
答案 0 :(得分:2)
@echo off
setlocal enableDelayedExpansion
set s=1234 1243 1324 1342 1432 1423 2134 2143 2314 2341 2431 2413 3214 3241 3124 3142 3412 3421 4231 4213 4321 4312 4132 4123
set num[1]=123
set num[2]=456
set num[3]=789
set num[4]=101
for %%a in (!s!) do (
set w=%%a
echo !w!
for /f %%g in ("num[!w:~0,1!]") do set fnum=!%%g!
echo !fnum!
)
答案 1 :(得分:1)
@ECHO OFF
setlocal enableDelayedExpansion
set s=1234 1243 1324 1342 1432 1423 2134 2143 2314 2341 2431 2413 3214 3241 3124 3142 3412 3421 4231 4213 4321 4312 4132 4123
set num[1]=123
set num[2]=456
set num[3]=789
set num[4]=101
for %%a in (%s%) do (
set w=%%a
echo !w!
CALL set fnum=%%num[!w:~0,1!]%%
echo !fnum!
)
GOTO :EOF
答案 2 :(得分:0)
@echo off
setlocal enableDelayedExpansion
set s=1234 1243 1324 1342 1432 1423 2134 2143 2314 2341 2431 2413 3214 3241 3124 3142 3412 3421 4231 4213 4321 4312 4132 4123
set num[1]=123
set num[2]=456
set num[3]=789
set num[4]=101
for %%a in (!s!) do (
set w=%%a
echo !w!
for /F %%w in ("!w:~0,1!") do set fnum=!num[%%w]!
echo !fnum!
)
Arrays, linked lists and other data structures in cmd.exe (batch) script