China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 06:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Wonderful] [Statistics of the Number of Occurrences of Batch Processing Characters] DigestI View 23,262 Replies 41
Floor 16 Posted 2006-11-30 02:49 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Everyone's code is very wonderful. Compared with my sort scheme, it is much more sophisticated. I will give you all points!
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 17 Posted 2006-11-30 02:53 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The plan I made is here
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 18 Posted 2006-11-30 02:58 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Redtek's use of shift shifting and the sequential display feature of set .

Increase the display of the most frequent occurrence ^_^

@echo off
setlocal EnableDelayedExpansion
set str=adadfdfseffserfefsefseetsdg

:loop
set str$=%str$% %str:~0,1% && set str=%str:~1%
if not "%str%" == "" goto loop

call :start %str$%
set .
echo The most frequent occurrence: %max%=%maxN%
pause
exit

:start
if == ( goto :eof ) else ( set /a .%1+=1 )
if !.%1! GTR !maxN! set maxN=!.%1!&&set max=.%1
shift
goto :start


Bug fixed

[ Last edited by zxcv on 2006-11-29 at 08:27 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
youxi01 +2 2006-11-30 05:30
Floor 19 Posted 2006-11-30 03:14 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Brother namejm on floor 17's plan "Make a batch script for content statistics in text" is being appreciated. The code inside is really interesting and wonderful ~~ : ) ) )

In response to Brother zxcv: The reason the code on my floor 15 didn't include the part for the most frequent occurrence is because I didn't know how to do it (whispering ~)

Really wonderful ~~ Learned from Brothers namejm and zxcv ~ : ) ) )
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 20 Posted 2006-11-30 03:18 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I'm learning on the fly
All are good examples of learning good role models
Floor 21 Posted 2006-11-30 03:33 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Great, everyone keep it up^_^
业精于勤而荒于嬉,形成于思而毁于随。
Floor 22 Posted 2006-11-30 03:48 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
if !.%1! GTR !maxN! set maxN=!.%1! && set max=.%1
if %%j GTR !l! set l=%%j & set m=%%i

The sentence from user namejm and zxcv is interesting~~

Find the largest number. If the value obtained is greater than the "variable storing the maximum value", it means the obtained number is larger, so it should replace the original value in the "variable storing the maximum value". After all the data has been "gone through", the value in the "variable storing the maximum value" will naturally be the largest value~:)

Appreciate and strongly support!!!
Learned a lot more, and communication has sparked many inspirations~
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 23 Posted 2006-11-30 04:13 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  Just tested the code on floor 18. Based on the code on floor 18, I increased the value of the str variable and set it to: set str=adadfdfseffserfefsefseetsdgdsfjkljdsklfjdsfdsgdsafdsaf, then ran the batch file, and the result was:

.a=4
.d=10
.e=6
.f=9
.g=2
.j=3
.k=2
.l=2
.r=1
.s=11
.t=1
The most frequent occurrence: .f=9
Press any key to continue. . .
Floor 24 Posted 2006-11-30 04:31 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
The latter ones are getting more and more exciting. Everyone gains a lot from such exchanges, learns quickly and it's also interesting.
It is suggested that everyone find more such problems in the future. The requirements should not be too difficult, focusing on participation.
Let's discuss whether we can add some honorary awards in each session in the future, such as:
Shortest code
Fastest speed
Strongest stability
Best creativity
And another type that no one can understand but can complete the function.
Give full play to everyone's divergent thinking from these perspectives. However, how to name such things...
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 25 Posted 2006-11-30 04:49 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
There is another kind that no one can understand clearly but can complete the function. Hehe, this non-willing to be helpless moderator, you did magic.
Floor 26 Posted 2006-11-30 05:08 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Then the moderator's name is "Unprecedented"~ Isn't this name great?
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 27 Posted 2006-11-30 05:20 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
The results with the most occurrences of MS are not quite right. Where is the problem?

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 28 Posted 2006-11-30 05:23 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Also post an immature piece of code to count the number of occurrences of each character:

Idea: First use the "function" test to get the length of variable str and save it as OSlen; then get the first character of variable str and save it as str0, then replace all str0 in variable str with empty, then get the length of str and save it as %num%, then the first character that appears is: %str0%, and the length is: %OSlen%-%num%, and so on.....


@echo off
setlocal EnableDelayedExpansion
set str=adadfdfseffserfefsefseetsdg
call :test %str%

for /l %%i in (0 1 100) do (
set /a OSlen=!num!
set str%%i=!str:~0,1!
call :test1 !str! !str%%i! %%i)

:exit
pause>nul
exit

:test
set /a num=0
set var=%1
for /l %%i in (1 1 100) do (
set var_=!var:~%%i,1!
if "!var_!"=="" set /a num=%%i &&goto :eof)
goto :eof

:test1
set var=%1
set var_=%2
set num_=%3
set str=!var:%var_%=!
if "%str%"=="" goto :exit
call :test %str%

set /a len%num_%=!OSlen!-!num!
echo Character %2 appears !len%num_%! times


[ Last edited by youxi01 on 2006-11-30 at 06:47 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-11-30 05:51
Floor 29 Posted 2006-11-30 05:29 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
I also post one using for /l!
@echo off&setlocal enabledelayedexpansion
set str=adadfdfseffserfefsefseetsdgdsfjkljdsklfjdsfdsgdsafdsaf

for /l %%i in (0,1,100) do (
if "!str:~%%i,1!"=="" goto end
call :define !str:~%%i,1!
set/a !str:~%%i,1!+=1
)

:end
for /l %%x in (1,1,%num%) do (
call set exchang=%%!%%x!%%
call echo !%%x!--%%!%%x!%%个
if !exchang! gtr !max! call set max=%%!%%x!%%&set maxstr=!%%x!)
echo.&echo.出现次数最多的是%maxstr%=%max%次
pause>nul&goto :eof

:define
if not defined %1 set/a num+=1&&set !num!=%1
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-11-30 05:52

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 30 Posted 2006-11-30 06:10 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Appreciate the code on floors 15 and 18, learned it! Made a little change to the above code, but the essence remains!

@echo off
setlocal EnableDelayedExpansion
set str=adadfdfseffserfefsefseetsdg

for /l %%i in (0 1 100) do (
if "!str:~%%i,1!"=="" goto :exit
set /a .!str:~%%i,1!+=1)
:exit
set.
for /f "delims== tokens=1,2" %%i in ('set.') do (
if %%j GTR !maxl! set /a maxl=%%j && set max=%%i)
echo The most frequent is %max:.=% character, total %maxl% times
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-11-30 08:31
Forum Jump: