全网最无聊最全的cmd batch教程,看了不要学哦(二)写一个简单的分词器 ‘2021/8/28‘修改

写一个简单的分词器,忘记在哪个贴抄了个上半部,后面再编辑, 下半部是本人写的,纯娱乐还没有讲解
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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值