Board logo

标题: 批处理for循环嵌套 麻烦看看哪里出错了? [打印本页]

作者: silience    时间: 2012-11-23 13:45     标题: 批处理for循环嵌套 麻烦看看哪里出错了?

  1. @echo off&setlocal enabledelayedexpansion
  2. for /l %%a in (1,1,26) do (
  3.     for /f "tokens=%%a" %%b 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 (
  4.        set _%%a=%%b
  5.     )
  6.   echo !_%%a!
  7. )
  8. pause
复制代码
===========
到没什么作用 就是把26个英文字母映射到"_1"——"_26"
作者: BAT-VBS    时间: 2012-11-23 14:01

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /l %%a in (1,1,26) do (
  4.     call :mapping %%a
  5. )
  6. pause
  7. goto :eof
  8. :mapping
  9. for /f "tokens=%1" %%b 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 (
  10.    set _%1=%%b
  11. )
  12. echo !_%1!
复制代码

作者: BAT-VBS    时间: 2012-11-23 14:06

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set n=0
  4. for %%a 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 (
  5.     set /a n+=1
  6.     set _!n!=%%a
  7. )
  8. set _
  9. pause
复制代码

作者: BAT-VBS    时间: 2012-11-23 14:08

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set n=0
  4. for %%a 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 (
  5.     set /a n+=1
  6.     set _!n!=%%a
  7. )
  8. for /l %%a in (1,1,!n!) do (
  9.     echo !_%%a!
  10. )
  11. pause
复制代码

作者: cutebe    时间: 2012-11-23 14:13

  1. @ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
  2. FOR /L %%A IN (1,1,26)DO (
  3.  SET N=
  4.  FOR %%B 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 (
  5.   SET/aN+=1
  6.   IF !N! EQU %%A SET _%%A=%%B
  7.  )
  8.  ECHO !_%%A!
  9. )
  10. PAUSE
复制代码
  1. @ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
  2. FOR %%B 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 (
  3.  SET/aN+=1
  4.  SET _!N!=%%B
  5. )
  6. FOR /L %%A IN (1,1,26)DO ECHO !_%%A!
  7. PAUSE
复制代码

作者: silience    时间: 2012-11-23 15:13

整的我头大。。。谢谢各位了 尤其是bat-vbs
作者: 悬崖之树    时间: 2012-12-4 18:36

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for %%a 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 (
  4.    set /a n+=1 & echo _!n!=%%a
  5. )
  6. pause>nul
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2