中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-28 11:38
47,813 topics / 349,918 posts / today 0 new / 48,277 members
DOS批处理 & 脚本技术(批处理室) » A character sorting problem for newbies (bonus question)
Printable Version  2,818 / 21
Floor1 bat-zw Posted 2008-05-21 10:22
金牌会员 Posts 1,276 Credits 3,105
There is a group of characters: 13 z 113 -3 778 10004 f k a 119 -101 8 -19 m
Requirement: Sort and output through batch processing: -101 -19 -3 8 13 113 119 778 10004 a f k m z
Try to use the method of not generating temporary files as much as possible.
PS: For the first new person who makes it, I will add 15 points.
----------------------------------------------------------------------------------------------------------
My answer:


[ Last edited by zw19750516 on 2008-5-21 at 08:19 PM ]
Floor2 bat-zw Posted 2008-05-21 12:05
金牌会员 Posts 1,276 Credits 3,105
Oh, I made this for newbies to activate everyone's thinking!
Floor3 jia332 Posted 2008-05-21 12:51
初级用户 Posts 81 Credits 160
@echo on
set var=13 z 113 -3 778 10004 f k a 119 -101 8 -19 m
for /f %%a in ('%var%') do (
set /a var1=%%a,var2=%%b, var3=%%c,var4=%%d,var5=%%e,var6=%%f,var7=%%g,var8=%%h, /a var9=%%i,var10=%%j,var11=%%k,var12=%%l,var13=%%m,var14=%%n
)
echo %var11% %var13% %var4% %var12% %var1% %var3% %var10% %var5% %var6% %var9% %var7% %var8% %var14% %var2%
pause

Why can't it get the value like this? Please ask experts for guidance.

[ Last edited by jia332 on 2008-5-21 at 12:53 PM ]
Floor4 bat-zw Posted 2008-05-21 12:55
金牌会员 Posts 1,276 Credits 3,105
1. There is an error in your code: When assigning values continuously with set, they should only be separated by &. For example, set a=1&set b=2.
2. It is better to directly do like this: echo -101 -19 -3 8 13 113 119 778 10004 a f k m z
Floor5 jia332 Posted 2008-05-21 12:58
初级用户 Posts 81 Credits 160
set /a a=1+1,b=2+1,c=3+1
echo %a% %b% %c%
Why is this okay, can zw19750516 teach the younger brother?
Floor6 terse Posted 2008-05-21 13:06
银牌会员 Posts 946 Credits 2,404
I can modify the previous one and it should be okay
Floor7 bat-zw Posted 2008-05-21 13:11
金牌会员 Posts 1,276 Credits 3,105
Please ask terse brother to leave more room for newcomers to think.
Floor8 clian76 Posted 2008-05-21 13:17
中级用户 Posts 162 Credits 363
Floor9 terse Posted 2008-05-21 13:32
银牌会员 Posts 946 Credits 2,404
Originally posted by zw19750516 at 2008-5-21 13:11:
Please leave more room for new users to think, Brother Terse.

So I didn't post it. These past two days, the stock market has plummeted, which has really messed me up. I'm not in the mood anymore. I'll just go watch the market for a while.
Floor10 zlmjh Posted 2008-05-21 14:01
新手上路 Posts 2 Credits 4
Floor11 jmz573515 Posted 2008-05-21 14:41
银牌会员 Posts 464 Credits 1,212
I can only write it like this...
Floor12 26933062 Posted 2008-05-21 14:43
银牌会员 Posts 879 Credits 2,268
Those who can solve this problem are at most new forum members, definitely not batch processing veterans.
Floor13 bat-zw Posted 2008-05-21 15:01
金牌会员 Posts 1,276 Credits 3,105
Agree with brother's statement. In fact, my ultimate goal is still to make the forum active.
ps: The code of jmz573515 can still be simplified.
Floor14 bat-zw Posted 2008-05-21 16:04
金牌会员 Posts 1,276 Credits 3,105
&& can be directly used with the method of comparing sizes. Please pay attention to the positioning and uniqueness of characters when sorting.
Floor15 pusofalse Posted 2008-05-21 17:01
银牌会员 Posts 646 Credits 1,604
My train of thought...
First extract the numbers and assign variables respectively, set for automatic sorting
Then judge which ones are not assigned variables, those not assigned are letters, the same as above, set for the second sorting...
Or create a new file, name them respectively with these letters, and then the dir /b o:n output command result~
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023