收藏 分销(赏)

查找字符出现次数.bat.doc

上传人:仙人****88 文档编号:8659800 上传时间:2025-02-24 格式:DOC 页数:2 大小:14.40KB 下载积分:10 金币
下载 相关
查找字符出现次数.bat.doc_第1页
第1页 / 共2页
查找字符出现次数.bat.doc_第2页
第2页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
@echo off ::专业的电脑医生原创 ::转载请说明 setlocal ENABLEDELAYEDEXPANSION set /p "str=请输入字符串:" set /p "char=请输入要统计的字符(串):" call:Length "%str%" "str_len" call:Length "%char%" "char_len" set /a "n=0" set /a "count=0" call:Find "%str%" "%char%" "%char_len%" "0" "pos" if "%pos%"=="-1" (echo 没找到。&pause>nul&exit /b 1) :loop set /a "count+=1" set /a "pos+=%char_len%" call:Find "%str%" "%char%" "%char_len%" "%pos%" "pos" if "%pos%"=="-1" goto:output goto:loop :output echo 共有%count%个匹配项。 pause>nul exit /b 0 :Length :: Length [str] [var] setlocal set /a "_str_n=0" set "__str=%~1" :_len_func if /i "!__str:~%_str_n%,1!"=="" goto:__end_func set /a "_str_n+=1" goto :_len_func :__end_func endlocal&set "%~2=%_str_n%" goto:EOF :Find :: Find [strCheck] [strMatch] [len] [start] [var] setlocal set "_strCheck=%~1"&set /a "_match_len=%~3"&set "_strMatch=%~2"&set "_temp_str=" set /a "_pos=%~4"&set /a "_temp_pos_check=0"&set /a "_temp_pos_match=0" :_find_loop ::ping /n 2 127.1>nul 2>nul if /i "!_strCheck:~%_pos%,1!"=="" (set /a "_pos=-2"&goto:_end_find) if /i "!_strCheck:~%_pos%,1!"=="!_strMatch:~0,1!" ( set /a "_pos-=1" set "_temp_str=!_strCheck:~%_pos%,%_match_len%!" if /i not "%_temp_str%"=="%_strMatch%" goto:_end_find else set /a "_pos+=1" ) else (set /a "_pos+=1"&goto:_find_loop) :_end_find endlocal&set /a "%~5=%_pos%+1" goto:EOF
展开阅读全文

开通  VIP、SVIP  下载更划算
下载10份以上建议开通 VIP 会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        关注我们

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服