[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. @echo off
  2. for /l %%i in (1,2,99) do echo.%%i
复制代码
第二题

TOP

回复 1楼 的帖子

为加快新手对for命令的入门,特编制本套"试题"(可以将答案作为回帖)
1、批处理运行窗口显示1~100 这100 个数字;
  1. @echo off
  2. for /l %%i in (1 1 100) do echo %%i
  3. pause
复制代码
2、批处理运行窗口显示 1、3、5.....99这50个数字;
  1. @echo off
  2. for /l %%i in (1 2 99) do echo %%i
  3. pause
复制代码
3、将 bbs bathome.net (在同一行)分成三行显示在批处理运行窗口;
  1. @echo off
  2. set str=bbs,bathome,net
  3. for %%i in (%str%) do echo %%i
  4. pause
复制代码

[ 本帖最后由 jsls 于 2010-7-2 09:42 编辑 ]
超级bat新手,bc问题别笑。
576715799

TOP

学习了,我也要继续努力。

TOP

值得学习下,先看看了

TOP

我的思路

1>
  1. @echo off
  2. for %%i in (bbs bathome .net) do echo %%i
  3. pause
复制代码
2>
  1. @echo off
  2. for %%i in ("e:\test.txt") do type %%i
  3. pause
复制代码

TOP

终于答完了,请老师阅卷,好有成就感啊。。。

  1. @echo off
  2. echo 问题1的答案:
  3. for /l %%i in (1,1,100) do set /p=%%i <nul
  4. echo/
  5. echo/
  6. echo 问题2的答案:
  7. for /l %%i in (1,2,99) do set /p=%%i <nul
  8. echo/
  9. echo/
  10. echo 问题3的答案:
  11. set s=bbs bathome.net
  12. set v=%s:.= %
  13. for %%i in (%v%) do (
  14.     echo %%i
  15. )
  16. echo/
  17. echo/
  18. echo 问题4的答案:
  19. echo ①:
  20. for /f "delims=" %%i in (f:\test.txt) do echo %%i
  21. echo ②:
  22. for /f "tokens=2" %%i in (f:\test.txt) do echo %%i
  23. pause>nul
复制代码

TOP

  1. @echo off
  2. for /f "tokens=1,2,3 delims=. " %%i in ("bbs bathome.net") do (echo %%i
  3. echo %%j
  4. echo %%k
  5. )
  6. pause
复制代码

TOP

  1. @echo off
  2. for %%i  in (bbs bathome net) do (
  3. echo %%i
  4. )
  5. for /l %%i in (1  1  100) do (ehco %%i)
  6. for  /l %%i in (1 2  99) do  (  echo %%i )
复制代码

TOP

  1. @echo off
  2. for /l %%i in (1,1,100) do echo %%i
  3. pause
复制代码
  1. @echo off
  2. for /l %%i in (1,2,99) do echo %%i
  3. pause
复制代码
  1. @echo off
  2. for /f "delims=, tokens=2" %%i in (test.txt) do echo %%i
  3. pause
复制代码
第三个问题不会了

TOP

  1. @echo off
  2. echo 第一题:
  3. for /l  %%i in (1,1,100) do  echo %%i
  4. echo 第二题:& pause >nul
  5. for /l  %%i in (1,2,99) do  echo %%i
  6. echo 第三题:& pause >nul
  7. set var=bbs bathome.net
  8. echo %var%
  9. for /f "tokens=1 " %%a in ("%var%") do echo %%a
  10. for /f "tokens=2 " %%b in ("%var%") do echo %%b
  11. for /f "tokens=3 " %%c in ("%var%") do echo %%c
  12. echo 第四题的第一小题:& pause >nul
  13. for /f "tokens=2" %%i in (f:\test.txt) do @echo %%i
  14. echo 第四题的第二小题:& pause >nul
  15. for /f "tokens=1-3" %%i in (f:\test.txt) do @echo %%i %%j %%k
  16. pause
复制代码

TOP

答案

  1. @echo off
  2. for /f "delims= tokens=1,2,3" %%i in (test.txt) do echo %%i
  3. pause
复制代码
本来以为这样执行的结果是只显示第一节也就是只显示147三个数字,没有想到竟全显示了,这是怎么回事?

TOP

//第一题
@echo off
for /l   %%i in (1,1,100) do echo %%i
pause>nul

//第二题

@echo off
for /l   %%i in (1,2,99) do echo %%i
pause>nul

//第三题
@echo off
for /f "tokens=1-3 delims=. "  %%i in ("bbs bathome.net") do (
echo %%i
echo %%j
echo %%k
)
pause>nul
//第四题
@echo off
for /f "tokens=1-3 delims=. "  %%i in (test.txt) do (echo %%i  %%j  %%k)
pause

@echo off
for /f "tokens=2 delims=. "  %%i in (test.txt) do (echo %%i  )
pause
1

评分人数

    • Batcher: 请编辑自己的帖子,把代码放到code标签里面 ...PB -2

TOP

@echo off
for /f "tokens=1-3 delims=. " %%a in ("bbs bathome.net") do echo %%a%%b
pause>nul

TOP

  1. 1.
  2. @echo off
  3. for /l %%I in (1,1,100) do echo %%I
  4. pause
  5. 2.
  6. @echo off
  7. for /l %%I in (1,2,99) do echo %%I
  8. pause
  9. 3.
  10. @echo off
  11. set var=bbs bathome.net
  12. echo %var%
  13. for /f "tokens=1,2,3 delims=. " %%I in ("%var%") do (
  14. echo %%I
  15. echo %%J
  16. echo %%K)
  17. pause
  18. 4.
  19. @echo off
  20. for /f "tokens=1-3" %%I in (F:\test.txt) do echo %%I %%J %%K
  21. for /f "tokens=2" %%I in (F:\test.txt) do echo %%I
  22. pause
复制代码

[ 本帖最后由 zsllq 于 2010-10-26 20:39 编辑 ]

TOP

1.
  1. @echo off
  2. for /l %%i in (1,1,100) do echo %%i
  3. pause
复制代码
2.
  1. @echo off
  2. for /l %%i in (1,2,99) do echo %%i
  3. pause
复制代码
3.
  1. @echo off
  2. set a=bbs bathome.net
  3. for /f %%i in ("%a%") do echo %%i
  4. for /f "tokens=2 delims=+. " %%i in ("%a%") do echo %%i
  5. for /f "tokens=3 delims=+. " %%i in ("%a%") do echo %%i
  6. pause
复制代码
4.1
  1. @echo off
  2. for /f "delims=" %%i in (f:\test.txt) do echo %%i
  3. pause
复制代码
4.2
  1. @echo off
  2. for /f "tokens=2" %%i in (f:\test.txt) do echo %%i
  3. pause
复制代码

[ 本帖最后由 lzx 于 2010-11-3 01:48 编辑 ]

TOP

返回列表