原帖由 dos时代菜鸟 于 2011-9-26 13:02 发表
如果能确定每一个字 都有空格相隔就好办多了。信息放到 x.txt 中
看看下面的:
@echo off & SETLOCAL ENABLEDELAYEDEXPANSION
set t=0 & set w=0 & set n=0
for /f "delims=" %%c in (x.txt) do (
for %%d in (%%c) do (
if %%d*==他* set /a t+=1
if %%d*==我* set /a w+=1
if %%d*==你* set /a n+=1
)
)
echo 他 %t%
echo 你 %n%
echo 我 %w%
原帖由 2011_sim 于 2011-9-26 14:34 发表
斗胆妄自精简一下:
@echo off
for /f delims^= %%c in (x.txt) do (
for %%d in (%%c) do (
if %%d*==他* set /a t+=1
if %%d*==我* set /a w+=1
if %%d*==你* set /a n+=1
))
(echo.他 % ...
原帖由 x9tian 于 2011-9-29 09:08 发表
再来个更精简的。。
(for /f "usebackq delims=" %%i in ("%~dp0文本.txt") do (for %%a in (%%i) do if not defined %%a (set/a _%%a+=1) else set /a _%%a=+=1))&&set _
原帖由 x9tian 于 2011-9-29 09:08 发表
再来个更精简的。。
(for /f "usebackq delims=" %%i in ("%~dp0文本.txt") do (for %%a in (%%i) do if not defined %%a (set/a _%%a+=1) else set /a _%%a=+=1))&&set _
原帖由 2011_sim 于 2011-9-30 11:32 发表
(for /f "usebackq delims=" %%i in ("%~dp01.txt") do (for %%a in (%%i) do if not defined %%a (set/a _%%a+=1) else set /a _%%a:+=1))&&(set _)>目标文件.txt
原帖由 <i>2011xiao8xiao</i> 于 2011-9-30 13:35 发表 <a href="http://bbs.wuyou.net/redirect.php?goto=findpost&pid=2312428&ptid=199541" target="_blank"><img src="http://bbs.wuyou.net/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" /></a><br />
<br />
<br />
越来越接近理想了,还差一步就完工了 ^o^ 那就是希望能够排序,从最高次数排下来。<br />
<br />
再次感谢伸出援手相助的人!!!谢谢你们了!
原帖由 <i>2011_sim</i> 于 2011-9-29 09:45 发表 <a href="http://bbs.wuyou.net/redirect.php?goto=findpost&pid=2311792&ptid=199541" target="_blank"><img src="http://bbs.wuyou.net/images/common/back.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" /></a><br />
<br />
<br />
这段代码构思巧妙!!佩服!<br />
另外: 发现一个bug或者是x9tian 兄笔误<br />
else set /a _%%a=+=1第一个=会被当作赋值符=,当条件不成立时可能会造成找不到操作数的错误。<br />
可能我理解有误,不当之处请指正。
欢迎光临 无忧启动论坛 (http://wuyou.net/) | Powered by Discuz! X3.3 |