Multiple variable nested test experiment, version: Yunyun version ~:)
@echo off
cls
set num=Redtek 2006 bbs.cn-dos.net
set a=12345
set b=654321
echo ● Variable test:
echo.
echo ● Want to get ^%num:~5,1^%, that is: take the value of variable num starting from offset 5, take 1 character, the result: k
echo According to the above principle, test variable nested variable value taking without using delayed variables.
echo.
echo ● Now we set that the ~5 in ^%num:~5,1^% should come from another variable b indirectly.
echo So, ^%num:~5,1^% should (pseudocode) be expressed as: ^%num:~b,1^%, but there are multiple values in variable b,
echo We only want to take the first element from offset 0 in variable b, which is 5. We have started nested variables.
echo So we need to nest the statement to get variable b (^%b:~1,1^%) in the variable value taking statement of num again.
echo.
echo That is: taking a certain character in variable num should be determined by another variable b from where to start taking.
echo But, we also need to nest variables, that is:
echo The character value in variable b that determines which character in variable num to take is determined, so we need to decompose b again,
echo In this way, it is a three-level nested variable relationship, and they influence and nest variables layer by layer, haha...
echo.
echo ● So, we use multi-level test to display the whole process of value taking evolution ~:)
echo.
echo The following are the results of four "asymptotic" evaluation processes, and finally it takes 3 Calls to find out these nested variables ~:)
echo.
echo %%%%%%%%num:~%%%%b:~%a:~0,1%,1%%%%,1%%%%%%%%
call echo %%%%%%%%num:~%%%%b:~%a:~0,1%,1%%%%,1%%%%%%%%
call call echo %%%%%%%%num:~%%%%b:~%a:~0,1%,1%%%%,1%%%%%%%%
call call call echo The final value is: %%%%%%%%num:~%%%%b:~%a:~0,1%,1%%%%,1%%%%%%%%
rem In theory, we can Call it n times, so we can nest variables randomly in variables ~:)
rem The above is an experimental process of "Yunyun" to have a deeper understanding of nested variables ~:)
The test output value results are as follows:
%%%%num:~%%b:~1,1%%,1%%%%
%%num:~%b:~1,1%,1%%
%num:~5,1%
The final value is: k
The above experimental variable nesting requires 4 "actions" to completely "transform" and display the actual desired value ~:)
Simple principle explanation: The character value taken from variable num is determined by another variable b, and the orientation of a certain character value in variable b is determined by variable a again.
Rule: %% two percent signs are used for output, which represents one % sign,
If you want to output %% two percent signs, you need to use four percent signs.
Using the above principle, use different quantities of % percent signs to determine the level of variable nesting,
The more levels, the double use quantity of percent signs also increases accordingly, and this principle can be used to complete extremely complex nesting.
Disadvantage: The more complex the nesting, the more difficult it is to read clearly, and the more difficult it is to maintain the code.
So, another advantage of using delayed variables is that the code can be very clear ~:)
[
Last edited by redtek on 2006-11-21 at 09:53 AM ]