Loop through ASCII codes in batch file

2019-04-06 04:40发布

I want to echo A to Z without typing 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 such long and unfruitful commands out. So I was wondering if i can cycle through ASCII codes. Something like for %%J in (ASCII of A ie.65 to Z) do echo %%J

Any help would be appreciated.

7条回答
Root(大扎)
2楼-- · 2019-04-06 05:13

This little gem comes to mind as it is not obfuscated and reasonably performant:

@set _ASCII=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

@for %%J in (%_ASCII%) do @echo %%J

Separate the data from the program flow logic and it reads better. Run time is under a microsecond on my system, about one order of magnitude faster than the other schemes.

The only type casting that Windows Batch scripts can do is when it momentarily promotes strings to integer and then back to string again.

查看更多
登录 后发表回答