[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

批处理产生001到999之间的数字

如下
001
002
003
...
999
ㄗs:A good programming is 99% sweat and 1% coffee!--①個亾

============ >   hi.baidu.com/novaa   <============

@echo off&setlocal enabledelayedexpansion
for /l %%i in (1 1 999) do (
        set var=00%%i
        set var=!var:~-3!
        echo !var!
)
pause>nul

TOP

for /l %%i in (1 1 999) do (set var=000%%i&call echo %%var:~-3%%)

TOP

@echo off
for /l %%i in (1 1 999) do (set var=00%%i && call echo %%var:~-4%%)
pause

TOP

@echo off
for /l %%i in (1 1 999) do (
        set "var=00%%i"
        call echo %%var:~-3%%
)
pause>nul

TOP

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1 1 999) do (
        set var=00%%i
        echo !var:~-3!
)
pause>nul

TOP

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1001,1,1999) do (
        set var=%%i
        echo !var:~1!
)
pause

TOP

回复 1# novaa
  1. @echo off
  2. set a=1
  3. set b=10
  4. set c=100
  5. :loop1
  6. echo 00%a%
  7. set /a a=%a%+1
  8. if "%a%"=="9" goto loop2
  9. :loop2
  10. echo 0%b%
  11. set /a b=%b%+1
  12. if "b"=="99" goto loop3
  13. :loop3
  14. echo %c%
  15. set /a c=%c%+1
  16. if "%c%"=="999" goto pause
  17. :pause
  18. pause>nul
复制代码

TOP

@ECHO OFf&title by author Gan&rem 9:37 2019/9/29

setlocal enabledelayedexpansion
(for /l %%a in (0,1,999) do (set nu1=%%a
if !nu1! lss 100 ( set nu1=00!nu1!&echo !nu1:~-3!)else echo %%a
))>result.txt
pause

TOP

  1. @echo off
  2. for /l %%i in ( 001 1 999 ) do echo %%i
复制代码

TOP

  1. @echo off
  2. for /l %%i in (1, 1, 999) do (
  3. if %%i LSS 10 (
  4. echo 00%%i
  5. ) else if %%i LSS 100 (
  6. echo 0%%i
  7. ) else (
  8. echo %%i
  9. )
  10. )
复制代码
1

评分人数

TOP

@echo off
setlocal enabledelayedexpansion
for /l %%a in (1,1,999) do (
set n=%%a
if !n! lss 10 (
set n=0!n!
  )
if !n! lss 100 (
set n=0!n!
)
echo !n!
)
pause

TOP

  1. @echo off
  2. :eo
  3. cls
  4. echo %random:~-1%%random:~-1%%random:~-1%
  5. pause
  6. goto :eo
复制代码
不记得参考论坛哪位大神思维了。

TOP

  1. @Echo off
  2. for /l %%a in (0 1 9) do ^
  3. for /l %%b in (0 1 9) do ^
  4. for /l %%c in (0 1 9) do ^
  5. Echo %%a%%b%%c
  6. Pause
复制代码
2

评分人数

    • codegay: 1技术 + 1
    • happy886rr: 这种写法我还是第一次见,好厉害的for技术 + 1

TOP

低语言代码优化:
  1. @echo off
  2. call:1 999
  3. pause
  4. exit
  5. :1
  6. set "n=-1"
  7. :2
  8. set/a "n+=1"
  9. set "m=0000000000%n%"
  10. echo,%m:~-3%
  11. if %n%==%* goto:eof
  12. goto:2
复制代码
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

返回列表