bat批处理 tokens最大值31的修复

@echo off&setlocal enabledelayedexpansion
set err=0
for /f "delims=" %%a in (
    "Letter\0Letter Small\0Tabloid\0Ledger\0Legal\0Statement\0Executive\0A3\0A4\0A4 Small\0A5\0B4 (JIS)\0B5 (JIS)\0Folio\0Quarto\010x14\011x17\0Note\0Envelope #9\0Envelope #10\0Envelope #11\0Envelope #12\0Envelope #14\0C size sheet\0D size sheet\0E size sheet\0Envelope DL\0Envelope C5\0Envelope C3\0Envelope C4\0Envelope C6\0Envelope C65\0Envelope B4\0Envelope B5\0Envelope B6\0Envelope Italy\0Envelope Monarch\06 3/4 Envelope\0US Std Fanfold\0German Std Fanfold\0German Legal Fanfold\0B4 (ISO)\0Japanese Postcard\09x11\010x11\011x15\0Envelope Invite\0Letter Extra\0Legal Extra\0Tabloid Extra\0A4 Extra\0Letter Transverse\0A4 Transverse\0Letter Extra Transverse\0SuperA/SuperA/A4\0SuperB/SuperB/A3\0Letter Plus\0A4 Plus\0A5 Transverse\0B5 (JIS) Transverse\0A3 Extra\0A5 Extra\0B5 (ISO) Extra\0A2\0A3 Transverse\0A3 Extra Transverse\0A0\0A0+\0A1\0A1+\0ANSI A\0ANSI B\0ANSI C\0ANSI D\0ANSI E\0ARCH A\0ARCH B\0ARCH C\0ARCH D\0ARCH E
"
) do (
    set char=%%a
    set char=!char:\0=,!
)

for /l %%a in (1,1,9999) do (
    if !err! equ 1 (
        goto allend
    )
    set /a num+=1
    if !num! equ 32 (
        for /f "delims=" %%c in ("!done_char!") do (
            set char=!char:%%c=!
            set done_char=
            set num=1
        )
    )
    call :type_char
    )
)

:allend
set /p=allend.

:type_char
set err=1
for /f "delims=, tokens=%num%" %%b in ("!char!") do (
    set done_char=!done_char!%%b,
    echo %%b
    set err=0
)

运行结果:
bat批处理 tokens最大值31的修复_第1张图片

自创方法,原理很简单,就是先读取完31个tokens后,把之前读取过的通过set删除掉。
然后又开始重复读取31次,直到卡变量发现读不出了就停止读取。

注意:for /l参数最大值9999,多了就跳不出循环了。

你可能感兴趣的:(笔记)