k515413928 当前离线
一级士官
@echo off setlocal Enabledelayedexpansion ::例如去某文本含有字符0的行并赋值给KK ::得到的值将寄存在KK1~ KK0为数组总个数 call :G_getstrrow 0 a.txt kk echo %kk1% echo %kk0% pause exit ::1.取文本行中指定的第N行 G_getrowstr 行数 文本 返回寄存变量 ::2.取文本的总行数 G_getrows 文本 返回寄存变量 ::3.合并多个字符串字符串 G_mergestr 返回寄存变量 字符串1 字符串2 ... ::4.将某字符串插入某文本尾部 G_inserttail 文本 字符串1 字符串2 ... ::5.统计文本长度G_counttxt 文本 返回长度变量 ::6.统计变量长度G_countstr 变量 返回长度 ::7.取文本出现行G_getstrrow 字符串 文本 寄存 (返回数组总个数保存 在0位) ::7 :G_getstrrow set G_getstrrowsum= set G_getstrrowtmp= set G_getstrrowtmps= set G_getstrrows=%3 for /f "delims=" %%i in ('findstr "%1" %2') do ( set /a "G_getstrrowsum+=1" set G_getstrrowtmp=%%i call :G_mergestr getstrrowtmpa %G_getstrrows% !G_getstrrowsum! call :G_getstrrow_set !getstrrowtmpa! ) set %G_getstrrows%0=!G_getstrrowsum! set G_getstrrows= set G_getstrrowtmp= set G_getstrrowtmps= goto :eof :G_getstrrow_set set G_getstrrowtmps=%1 set %G_getstrrowtmps%=!G_getstrrowtmp! goto :eof ::6 :G_countstr set G_string=%1 set G_countstr=%2 :G_countstrstart if not "%G_string%"=="" ( set /a %G_countstr%+=1 set "G_string=%G_string:~1%" goto G_countstrstart ) set G_string= set G_countstr= goto :eof ::5 :G_counttxt set G_counttxt= set G_count=%2 for /f "delims=" %%i in (%1) do set G_counttxt=!G_counttxt!%%i :G_counttxtstart if not "%G_counttxt%"=="" ( set /a %G_count%+=1 set "G_counttxt=%G_counttxt:~1%" goto G_counttxtstart ) set G_count= set G_counttxt= goto :eof ::1 :G_getrowstr set %3= for /f "skip=%1 delims=" %%i in (%2) do ( set %3=%%i goto :eof ) ::2 :G_getrows set %2=0 for /f %%i in ('findstr /n .* %1') do ( set /a %2=%2+1 ) goto :eof ::3 :G_mergestr set G_mergestr=%1 :G_getstr if "%2"=="" goto mergestrend set G_mergestrs=%G_mergestrs%%2 shift /2 goto G_getstr :mergestrend set %G_mergestr%=%G_mergestrs% set G_mergestrs= goto :eof ::4 :G_inserttail set G_inserttailtxt=%1 :getG_inserttail if "%2"=="" goto G_inserttailend echo %2 >>%G_inserttailtxt% shift /2 goto getG_inserttail :G_inserttailend set G_inserttailtxt= goto :eof复制代码
TOP