中国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-14 00:21
47,812 topics / 349,916 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » A batch script for sequentially converting strings [Original]
Printable Version  3,563 / 9
Floor1 willsort Posted 2004-01-29 00:00
元老会员 Posts 1,512 Credits 4,432
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
Floor2 Kinglion Posted 2004-01-30 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
Benefited a lot, thank you.
Floor3 GOTOmsdos Posted 2004-02-03 00:00
铂金会员 Posts 1,827 Credits 5,154
There are many questions. Can each sentence be explained in detail so that more people can learn?
Floor4 xiaojun Posted 2004-02-03 00:00
银牌会员 Posts 499 Credits 2,202
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?
Floor5 willsort Posted 2004-02-03 00:00
元老会员 Posts 1,512 Credits 4,432
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.

Floor6 willsort Posted 2004-02-03 00:00
元老会员 Posts 1,512 Credits 4,432
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.
Floor7 willsort Posted 2004-02-03 00:00
元老会员 Posts 1,512 Credits 4,432
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.
Floor8 SagInvoker Posted 2004-05-24 00:00
初级用户 Posts 38 Credits 257
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~~~~~~
Floor9 chenall Posted 2004-05-26 00:00
银牌会员 Posts 469 Credits 1,276 From 福建泉州
Floor10 willsort Posted 2004-06-02 00:00
元老会员 Posts 1,512 Credits 4,432
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.

[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023