写一个简单的分词器,忘记在哪个贴抄了个上半部,后面再编辑, 下半部是本人写的,纯娱乐还没有讲解
textspliter.bat
@echo off
setlocal EnableDelayedExpansion
set str="helloworld "
set tempstr=%str%
set count=0
:loop
if defined tempstr (
set tempstr=%tempstr:~1%
set /a count+=1
set /a pos=%count%-1
set t!count!=!str:~%pos%,1!
goto loop
)
:: check the generated variables
:: echo %t10%
:: thx for >> https://stackoverflow.com/questions/26576914/windows-batch-split-string-to-individual-characters-to-variables
:: emmmm 之后我会再查查 关于 set t!count!=!str:~%pos%,1! 的用法,大致就是用这句组成数组的,在哪些大神面前我还是小白,班门弄斧了
::for /l %%i in (4,1,13) do for /f "delims=" %%j in ("t%%i") do for /f "tokens=2 delims==" %%k in ('set %%j') do echo %%k
set /a idx=4
set /a tmp=4
set x=0
:addnum
set /a end=%tmp%
:start
echo idx%idx%,end%end%
echo ################################################
for /l %%i in (%idx%,1,%end%) do for /f "delims=" %%j in ("t%%i") do for /f "tokens=2 delims==" %%k in ('set %%j') do for /f "tokens=2 delims==" %%l in ('set x') do @set x & @set x=%%l%%k
for /f "delims=0" %%i in ("%x%") do for /f "delims=" %%j in (textlist.txt) do if "%%i"=="%%j" echo match %%i
if "%idx%"== "13" goto fin
if %end%==13 set /a idx=%idx%+1 & set /a tmp=%tmp%+1 & goto addnum
@set /a end=%end%+1
set x=0
goto start
:fin
echo finish
textlist.txt
he
hell
hello
world
解释下这里的一些知识点
for /l 的意思是数字的for loop ,在cmd 觉得挺少用的上小数点的,所以只是整数递增, for /f 就是标准的 for in 语法(cmd 其实for /)
打开bat 显示的结果是 match 什么什么,就是从 helloworld里面分出来的词,其实有很多bug,只是纯娱乐,enjoy!