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-07-21 18:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A character sorting problem for newbies (bonus question) View 2,377 Replies 21
Original Poster Posted 2008-05-21 10:22 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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:

@echo off&setlocal enabledelayedexpansion
set str=13 z 113 -3 778 10004 f k a 119 -101 8 -19 m
echo Before sorting: %str%
for %%i in (%str%) do call,set var=!var! #%%i#
for %%i in (%var%) do set a=%%i&call :lp
echo After sorting: %var:#=%
pause>nul&goto :eof
:lp
for %%i in (%var%) do (
set b=%%i&set b=!b:#=!&set c=!a:#=!
if !b! lss !c! (
set var=!var:%a% =!
set var=!var:%%i=%%i %a%!
) else (
set var=!var!
)
)


[ Last edited by zw19750516 on 2008-5-21 at 08:19 PM ]
批处理之家新域名:www.bathome.net
Floor 2 Posted 2008-05-21 12:05 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Oh, I made this for newbies to activate everyone's thinking!
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-05-21 12:51 ·  中国 上海 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
19-year member
UID 59377
Gender Male
Status Offline
@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 ]
Floor 4 Posted 2008-05-21 12:55 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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
批处理之家新域名:www.bathome.net
Floor 5 Posted 2008-05-21 12:58 ·  中国 上海 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
19-year member
UID 59377
Gender Male
Status Offline
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?
Floor 6 Posted 2008-05-21 13:06 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
I can modify the previous one and it should be okay
简单!简单!再简单!
Floor 7 Posted 2008-05-21 13:11 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Please ask terse brother to leave more room for newcomers to think.
批处理之家新域名:www.bathome.net
Floor 8 Posted 2008-05-21 13:17 ·  中国 重庆 联通
中级用户
★★
Credits 363
Posts 162
Joined 2007-04-22 21:31
19-year member
UID 86104
Gender Male
Status Offline
Floor 9 Posted 2008-05-21 13:32 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
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.
简单!简单!再简单!
Floor 10 Posted 2008-05-21 14:01 ·  中国 新疆 伊犁哈萨克自治州 伊宁市 电信
新手上路
Credits 4
Posts 2
Joined 2008-05-20 07:07
18-year member
UID 119153
Gender Male
Status Offline
Floor 11 Posted 2008-05-21 14:41 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
I can only write it like this...

@echo off
setlocal enabledelayedexpansion
set i=1
set text="13 z 113 -3 778 10004 f k a 119 -101 8 -19 m"
:loop
for /f "tokens=1,* delims= " %%i in (%text%) do (
set a%i%=%%i
set text="%%j"
set /a i+=1
)
if !text! neq "" goto loop
set /a i-=1
for /l %%a in (1,1,%i%) do (
for /l %%b in (1,1,%i%) do (
if !a%%a! lss !a%%b! (
set tm=!a%%a!
set a%%a=!a%%b!
set a%%b=!tm!
)
)
)
for /l %%c in (1,1,%i%) do set /p=!a%%c! <nul
echo.
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
bat-zw +3 2008-05-21 15:02
Floor 12 Posted 2008-05-21 14:43 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Those who can solve this problem are at most new forum members, definitely not batch processing veterans.
致精致简!
Floor 13 Posted 2008-05-21 15:01 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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.
批处理之家新域名:www.bathome.net
Floor 14 Posted 2008-05-21 16:04 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
&& can be directly used with the method of comparing sizes. Please pay attention to the positioning and uniqueness of characters when sorting.
批处理之家新域名:www.bathome.net
Floor 15 Posted 2008-05-21 17:01 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
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~
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Forum Jump: