如何将字母顺序添加到菜单或选项

问题描述 投票:0回答:1

我已经知道向菜单或选项添加字母顺序(使用 ExitCodeAscii link),但这种方法会使输出变慢。

有人知道这个问题的快速方法和简单代码吗?

我已经尝试过这段代码:(只是示例)

@echo off
set "AZ1=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "AZ2=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set "menu= one two three four five"
for %%A in (%AZ2%) do for %%M in (%menu%) do echo [%%A] %%M
pause

The output:
[A] one
[A] two
[A] three
[A] four
[A] five
[B] one
[B] two
[B] three
etc...

I want the output:
[A] one
[B] two
[C] three
[D] four
[E] five
batch-file
1个回答
0
投票

每次运行外部循环时都会执行内部

for
循环。你不想这样。
保留使用计数器的原始方法,但不使用计数器本身,而是使用它从字母字符串中提取单个字符:

@echo off
setlocal enabledelayedexpansion
set "AZ1= ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "menu= one two three four five"
set count=0
for %%M in (%menu%) do (
  set /a count+=1
  call echo [%%AZ1:~!count!,1%%]  %%M
)
© www.soinside.com 2019 - 2024. All rights reserved.