- @echo off
- set info=互助互利,支付宝扫码头像,感谢赞助
- rem 有问题,可加QQ956535081及时沟通
- title %info%
- set "rootpath=%~dp0"
- cd /d "%rootpath%"
- powershell -NoProfile -ExecutionPolicy bypass ^
- function getcount($str,$word){^
- $index=0;^
- $count=0;^
- while(($index=$str.IndexOf($word, $index)) -ne -1){^
- $count++;^
- $index=$index+$word.Length;^
- };^
- return $count;^
- };^
- $file1='原件.txt';^
- $file2='关键词.txt';^
- $file3='统计结果.txt';^
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,int]';^
- $text1=[IO.File]::ReadAllLines($file1,[Text.Encoding]::Default);^
- $text2=[IO.File]::ReadAllLines($file2,[Text.Encoding]::Default);^
- for($i=0;$i -lt $text1.count;$i++){^
- for($j=0;$j -lt $text2.count;$j++){^
- $c=getcount $text1[$i] $text2[$j];^
- if(-not $dic.ContainsKey($text2[$j])){^
- $dic.add($text2[$j], $c);^
- }else{^
- $dic[$text2[$j]]+=$c;^
- };^
- };^
- };^
- [System.Collections.ArrayList]$s=@();^
- foreach($it in $dic.keys){[void]$s.add($it+' '+$dic[$it])};^
- [IO.File]::WriteAllLines($file3, $s, [Text.Encoding]::Default);^
- $dic;
- echo;%info%
- pause
复制代码
|