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-30 14:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A batch script for sequentially converting strings [Original] View 3,234 Replies 9
Original Poster Posted 2004-01-29 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
To All:


::This program is written for the sequential conversion of string values in batch processing, generally called as a subroutine by other programs, and can also be slightly modified and added as a sub-module call in a specific batch processing program.
@echo off
if == goto %2
if == goto nullargu

:main Main module: The count and match parameter lists can be reset and increased or decreased as needed
set factor=%1
call %0 $ count 1 2 3 4 5 7 8 9
call %0 $ match c d e f g h i j
goto display

:count Counting module: Set variable values #a1, #a2 according to the specified parameter factor
if == goto overflow
set #a1=%#a1%-
if not == goto count_2
set #a1=
set #a2=%#a2%+
if == goto overflow
:count_2
if == goto end
shift
goto count

:match Matching module: Loop to increment variables #b1, #b2. If they are equal to #a1 and #a2 respectively, the specified result value is the current loop parameter 3.
if == goto overflow
set #b1=%#b1%-
if not == goto match_2
set #b1=
set #b2=%#b2%+
if == goto overflow
:match_2
if == if == set result=%3
if not == goto end
shift
goto match

:display Display module: Display the assigned result
if == echo %factor% convert %result%
set result=
set factor=
set error=
set #a1=
set #a2=
set #b1=
set #b2=
goto end

:nullargu
echo.
echo Error: argument 1 not specified.
echo.
goto end

verflow
echo.
echo Error: number is overflow.
set error=overflow
echo.
goto end

:end
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 2 Posted 2004-01-30 00:00 ·  中国 辽宁 沈阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
Benefited a lot, thank you.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 3 Posted 2004-02-03 00:00 ·  中国 江苏 扬州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
There are many questions. Can each sentence be explained in detail so that more people can learn?
Floor 4 Posted 2004-02-03 00:00 ·  中国 重庆 电信
银牌会员
★★★
Credits 2,202
Posts 499
Joined 2003-06-12 00:00
23-year member
UID 4876
Gender Male
Status Offline
There are many doubts. Can each sentence be explained in detail so that more people can learn?

if == and if "%1"=="" are equivalent, right? ; Here, what does $ represent in if ==? (Money?
一年四季,枫叶红了又红;人生四季,失去的,还能再来吗?—— !
Floor 5 Posted 2004-02-03 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re xiaojun:

Are ==] and
They are equivalent, just different programming habits. I wanted to separate the representation of variable values from constant strings, but many people don't think it's necessary, and I can't force it.

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2004-02-03 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re xiaojun:

What does $ represent here in if ==? (Money?

$ has nothing to do with money, you really have imagination. This just means that the current running state is running in a subroutine, $ is a deformation of the first letter abbreviation of SUBROUTINE, this is also a matter of habit.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2004-02-03 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re xiaojun:

It's a huge workload if we really need to explain every sentence in detail, and I'm already short on time.

At present, such programs are only for enthusiasts to exchange ideas with each other, not suitable for popularization.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2004-05-24 00:00 ·  中国 重庆 南岸区 电信
初级用户
Credits 257
Posts 38
Joined 2004-05-20 00:00
22-year member
UID 24855
Gender Male
Status Offline
After reading it, I think the idea is good, but there's a problem. What do your #a2 and #b2 do???

If SHIFT is used 8 times and becomes ,
can't be accumulated to at all
So
set #a1=
set #a2=%#a2%+
if == goto overflow
There's no chance to execute it at all, unless you assign a value to #a1 at the beginning, but that's unlikely, right??
The same goes for #b2
So I really can't figure out what the purpose of setting #a2 and #b2 is
I don't know if you have anything else to say, let's hear it~~~~~~
Floor 9 Posted 2004-05-26 00:00 ·  中国 福建 泉州 石狮市 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
QQ:366840202
http://chenall.net
Floor 10 Posted 2004-06-02 00:00 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re SagInvoker:

Thanks to Brother SagInvoker for paying attention to this issue and putting forward your valuable opinions.

First of all, it needs to be stated that the sample program provided on the first floor is just a sample, not a general-purpose program. Therefore, it cannot handle various user needs by default, but users need to modify the source code according to their own needs.

The conversion sequence can be reset and adjusted in the main module of the program. In other words, if it is applied to your own project, you need to adjust the conversion sequence according to your own needs. Most of the time, this work is necessary. The 12345678 and cdefghij I used in the text are just examples with great limitations.

However, as for the program itself, it should try to consider various frequently occurring situations as much as possible to enhance its adaptability. For example, the conversion sequence in actual situations may be longer than 10 characters (such as the conversion from the alphabet to the ASCII code table). The environment variables #a2 and #b2 used in my program are exactly to solve the problem of long sequence conversion. Because the system's environment space is limited, if we completely count the conversion sequence as environment variables of corresponding lengths, it will cause the environment space to be overused. So I designed #a2 and #b2 as the tens digit of the sequence index, and #a1 and #b1 as the units digit. The code you have doubts about realizes the carry operation from #a1 to #a2, which is needed in many situations.

So although the code in the program will not be executed during the demonstration, it does not mean that it will not be executed in all cases. Even if these other situations require modifying the original code.

Of course, the program itself can be further improved. For example, it can self-process user-defined conversion sequences without users having to change the source code. But as for a demonstrative project, these interface issues are not the focus of our attention. First, we need to complete the implementation of the core functions, and then we can consider the interface and framework issues.

Welcome Brother SagInvoker to improve this program. Simplifying the code or adding functions is all right.

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: