如何循环 ASCII 值(此处为字母表)并对其进行处理?
我想回显 A 到 Z,而不必像这样手动输入每个字符for %%J in (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) do echo %%J
所以我想知道是否可以循环使用 ASCII 代码。就像是for %%J in (ASCII of A ie.65 to Z) do echo %%J
任何帮助,将不胜感激。
Surprisingly, there is a solution that makes use of an undocumented built-in environment variable named =ExitCodeAscii
, which holds the ASCII character of the current exit code1 (ErrorLevel
):
@echo off
for /L %%A in (65,1,90) do (
cmd /C exit %%A
call echo %%^=ExitCodeAscii%%
)
The for /L
循环遍历(十进制)字符代码A
to Z
. cmd /C exit %%A
设置返回码(ErrorLevel
) 到当前迭代的代码,即echo
-ed 之后作为一个角色。call
,与双%
-signs 为命令行引入第二个解析阶段,以便获取当前值=ExitCodeAscii
而不是整个面前的那个for /L
循环被执行(这将通过一个简单的命令行发生,例如echo %=ExitCodeAscii%
)。或者,延迟扩张也可以用。
基本思想归功于rojo并在这篇文章中应用:如何批量获得随机字母输出.
1) The exit code (or return code) is not necessarily the same thing as the ErrorLevel
value. However, the command line cmd /C exit 1
sets both values to 1
. To ensure that the exit code equals ErrorLevel
, use something like cmd /C exit %ErrorLevel%
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)