呵呵我来个可以查询整个文本的。
可以找出出现在文本的哪行且在该行的位置。
太多变量了。有点乱。呵呵。欢迎测试!
-
- @echo off&setlocal enabledelayedexpansion
- set /p sStrQ=请输入你想查的字符串:
- set iNum=0
- set "StrQ=!sStrQ!*"
- call :GetNum
- set Line=0
- for /f "delims=" %%i in ('findstr /n .* 1.txt') do (
- set /a Line=!Line!+1
- set sStrL=%%i
- set sStrL1=!sStrL:%sStrQ%=!
- if not "!sStrL1!"=="!sStrL!" (
- set sStrLp=!sStrL:%sStrQ%=#!
- set iPnum=1
- call :GetPosition
- call :Echo
- )
- )
- :GetNum
- set sStr=!StrQ:~0,1!
- set StrQ=!StrQ:~1!
- if not "!sStr!"=="*" (set /a iNum=!iNum!+1) else (goto :eof)
- goto :GetNum
- :GetPosition
- set sStrLp1=!sStrLp:~0,1!
- set sStrLp=!sStrLp:~1!
- if not "!sStrLp1!"=="#" (set /a iPnum=!iPnum!+1) else (goto :eof)
- goto :GetPosition
- :Echo
- echo 此字符串出现在第!Line!行第!iPnum!位置.
- echo\&echo\
- set EndL=iPnum!+!iNum!
- echo 此字符串结束在!EndL!位置
- echo\&echo\
- echo 任意键继续
- pause>nul
- goto :eof
-
-
-
复制代码
|