Loop through ASCII codes in batch file

后端 未结 5 2089
囚心锁ツ
囚心锁ツ 2021-01-04 17:46

How do I loop through ASCII values (here, alphabets) and work on them?

I want to echo A to Z without having to type every character manually like for %%J in (

5条回答
  •  情歌与酒
    2021-01-04 18:29

    The simplest solution is to include this PowerShell one-liner in your bat script:

    powershell "[char[]](65..90)"
    

    It's not necessarily the fastest, though.


    Here's a VBScript solution similar to Hackoo's, but in a hybrid format not relying on writing an external .vbs file. Save it with a .bat extension. The cscript line is what triggers execution of the VBScript hybrid code.

    
    
        
    
    

    Or if you're more comfortable with JavaScript syntax, here's a Batch + JScript hybrid.

    @if (@CodeSection == @Batch) @then
    @echo off & setlocal
    
    cscript /nologo /e:JScript "%~f0"
    goto :EOF
    
    @end // end Batch / begin JScript
    
    for (var i=65; i<=90; i++) WSH.Echo(String.fromCharCode(i));
    

提交回复
热议问题