批處理新手入門導讀[視頻教程]批處理基礎視頻教程[視頻教程]VBS基礎視頻教程
[批處理文件精品]批處理版照片整理器[批處理文件精品]純批處理備份&還原驅動在線第三方下載
返回列表 發帖
題目更改后很簡單。
A1:
@echo off
set str=I love,bbs;bathome=net
for %%I in (%str%) do  echo "%%I"
pause

A2:
@echo off
set str=I love,bbs;bathome=net
for %%i in (%str%) do if %%i==net echo %%i
pause



最初的題目(條件str=I love,bbs;bathhome.net),難度高。

TOP

回復 13# qpzlsn


   你設置了STR變量就可以直接引用了啊

TOP

A1:
  1. @echo off
  2. set str=I love,bbs;bathome=net
  3. for %%i in (%str%) do echo %%i
  4. pause
復制代碼
A2:
  1. @echo off
  2. set str=I love,bbs;bathome=net
  3. for %%i in (%str%) do set var=%%i
  4. echo %var%
  5. pause
復制代碼

TOP

回復 1# namejm


    A1:
  1. @echo off
  2. set "str=I love,bbs;bathome.net"
  3. for /f "tokens=1,2,3,4,5 delims=,;. " %%a in ("%str%") do (
  4. echo,%%a
  5. echo,%%b
  6. echo,%%c
  7. echo,%%d
  8. echo,%%e)
  9. pause>nul
復制代碼
A2:
  1. @echo off
  2. set "str=I love,bbs;bathome.net"
  3. for /f "tokens=1,2,3,4,5 delims=,;. " %%a in ("%str%") do (
  4. echo,%%e)
  5. pause>nul
復制代碼

TOP

A1:
@echo off
echo 分隔符1:逗號
for %%i in (I,LOVE,BBS,BATHOME,NET) do echo %%i
echo ____________________________________________
echo 分隔符2:分號
for %%i in (I;LOVE;BBS;BATHOME;NET) do echo %%i
echo ____________________________________________
echo 分隔符3:等號
for %%i in (I=LOVE=BBS=BATHOME=NET) do echo %%i
echo ____________________________________________
echo 分隔符4:跳格鍵
for %%i in (I        LOVE        BBS        BATHOME        NET) do echo %%i
echo ____________________________________________
echo 分隔符5:空格
for %%i in (I LOVE BBS BATHOME NET) do echo %%i
echo ____________________________________________
echo 非分隔符:點
for %%i in (I.LOVE.BBS.BATHOME.NET) do echo %%i
echo ____________________________________________
pause

A2:
@echo off
set str=I,LOVE,BBS,BATHOME,NET
for %%i in (%str%) do (set a=%%i)
echo %a%
pause

TOP

回復 12# akiraakito


    這位老兄理解地好。謝謝

TOP

  1. set str=I love,bbs;bathome=net
  2. for %%a in (%str%) do (echo %%a)
復制代碼

TOP

本帖最后由 holley 于 2018-8-16 16:53 編輯

回復 1# namejm
A1:
  1. @echo off
  2. set str=I love,bbs;bathome=net
  3. for %%i in (%str%) do echo %%i
  4. pause
復制代碼
A2:
  1. @echo off
  2. set str=I love,bbs;bathome=net
  3. for %%i in (%str%) do if exist %%i echo %%i
  4. pause
復制代碼
A2亂試出來的,有點想加個不存在的出錯代碼提示,結果發現可以得到最后一個匹配值...

TOP

用for語句建立test1.txt、test2.txt和test3.txt三個文本文件。
@echo off
for %%a in (text1 text2 text3) do md %%a
pause

TOP

@echo off
setlocal enabledelayedexpansion
set str=I love,bbs;bathome.net
for %%i in (%str%) do (
set "bb=%%~xi" 2>null
echo.%%~ni
set /a "cc=%%~xi" 2>null&&echo.!bb:~1!
)
pause

TOP

A1:假設令 set str=I love,bbs;bathome=net,請分別顯示出I、love、bbs、bathome和net這五個字符串。目的:了解for語句用到了哪些符號作為元素的分隔符。
  1. @echo off
  2. set str="I love,bbs;bathome=net"
  3. for /f "tokens=1,2,3,4,5 delims=,;= " %%i in ( %str% ) do (
  4. echo %%i
  5. echo %%j
  6. echo %%k
  7. echo %%l
  8. echo %%m
  9. )
  10. pause>nul
復制代碼
A2:條件同A1,要求最后只顯示net這個字符串。目的:了解for語句的執行流程。
  1. @echo off
  2. set str="I love,bbs;bathome=net"
  3. for /f "tokens=5 delims=,;= " %%i in ( %str% ) do echo %%i
  4. pause>nul
復制代碼

TOP

@echo off
echo.新手試題上路中^^_^^……
set str=I love,bbs;bathome=net
for /f "tokens=1-5 delims=;=, " %%i in ("%str%") do echo %%i %%j %%k %%l %%m
:: 發現delims=;=,  里邊的空格必須放在最后,且放在 TOKENS后,如果沒有空格可以隨便寫
pause>nul
for /f "delims== tokens=2" %%i in ("%str%") do echo %%i
pause>nul
::
書山有路勤為徑,學海無涯苦作舟

TOP

練習A1:
@echo off
set str=I love,bbs;bathome=net
for %%i in (%str%) do echo %%i
pause

練習A2:
@echo off
set str=I love,bbs;bathome=net
for %%i in (%str%) do set str2=%%i
echo %str2%
pause

TOP

第一題:
照葫蘆畫瓢
@echo off
set str=I love,bbs;bathome=net
for %%i in (%str%) do echo "%%i"
pause

第二題還沒學會

TOP

set str=I love,bbs;bathome=net && @for /f "tokens=1-5 delims=,;=" %i in ("%str%") do @echo %i %j %k %l

TOP

返回列表
广西快乐双彩开奖结果查询今晚