:begin setlocal ENABLEDELAYEDEXPANSION set var=%2 if "%var%" == "" set /p var=輸入要顯示的行的字符數(shù): for /l %%i in (1,1,%var%) do set str=!str!. findstr /x %str% %1 pause>nul goto :eof
@echo off :: 顯示只有4個字符的文本行 :: test.txt中只有純字母,無空格,無空行 :: 因為是全文解析,所以效率低下 :: code by jm 2006-8-14 for /f %%i in (test.txt) do ( set str=%%i set var=%%i call :loop set num=0 ) pause goto :eof
:loop set var=%var:~0,-1% set /a num+=1 if not "%var%"=="" goto loop if %num% equ 4 echo %str% goto :eof
@echo off :: 通過首尾插入字符來判斷,效率較高 :: 適合行中帶空格的情況 :: 如果不插入字符,只判斷第5位的字符情況,會出錯 :: code by 3742668 setlocal ENABLEDELAYEDEXPANSION for /f "delims=" %%i in (test.txt) do ( set str=b%%ie if not "!str:~5,1!" == "" if "!str:~6,1!" == "" echo. %%i ) pause goto :eof