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-08-13 19:05
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. Ask about the usage of ! View 1,588 Replies 10
Original Poster Posted 2006-10-20 22:38 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 305
Posts 85
Joined 2005-05-23 00:00
21-year member
UID 39004
Gender Male
Status Offline























This is code from an elder in the forum, but I don't know how to use it, so I've been unable to use it. Which expert can explain it? It's best to explain in detail things like:!num!,!ii:~0,1!. How is! used? This %ii:~0,1% can be found in set /?, but does it mean the same if it's changed to!ii:~0,1!?

[ Last edited by yardian on 2006-10-21 at 00:16 ]
Floor 2 Posted 2006-10-21 04:54 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 305
Posts 85
Joined 2005-05-23 00:00
21-year member
UID 39004
Gender Male
Status Offline
Floor 3 Posted 2006-10-21 05:11 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
You look at this paragraph which is easier to understand.


@echo off
set /p ii=Please enter a string:
setlocal enabledelayedexpansion
set form=0
set ii=%ii%@
:go
if not "%ii:~0,1%"=="@" (
if /i "!ii:~0,3!"=="yes" set form=1
set ii=%ii:~1%
goto go
)
cls
if "%form%"=="1" (
echo yes
) else (
echo no
)
pause
Floor 4 Posted 2006-10-21 07:46 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
There is also a stupid method: )
Use the pre - defined strings to be searched by you,
Replace the same strings in the user - input content with them,
Replace them with a flag character that is not easy or unlikely for the user to appear,
Compare this character (replaced as the first character) with a pre - defined symbol (such as "氵"),
If there is this symbol, it means that the replacement is successful, which means that the user - input content contains YES,
If there is no this symbol, it means that the replacement is not successful, so it does not contain.
……


@echo %dbg% off && setlocal enabledelayedexpansion
set /p ii=Please enter a string:
set ii=%ii:*yes=氵% && set ii=%ii:~0,1%
if /i "!ii!"=="氵" (echo Found the yes character!) else (echo Did not find the yes character.)


[ Last edited by redtek on 2006 - 10 - 21 at 08:00 ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2006-10-21 07:58 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Originally posted by yardian at 2006-10-20 22:38:
:!num!,!ii:~0,1!.
How is ! used? This %ii:~0,1%, can be found from set /?. But does it mean the same when changing to !, like !ii:~0,1!?



%ii:~0,1% (meaning: take the first character of the %ii% variable, starting from offset 0)
      (its specific meaning needs to be queried in for /?, this FOR help is very comprehensive)
      (there are many kinds of usages, very many, a lot of words can't finish, need to run one by one according to the help to understand)

For other contents, please query the following help information:

SET /?

FOR /?

SETLOCAL /?

IF /?

Among them, FOR has detailed instructions on the use of the! symbol, but it also needs to be repeatedly understood and run and tested : )
Otherwise, it cannot be thoroughly understood : )
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 6 Posted 2006-10-21 11:09 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 305
Posts 85
Joined 2005-05-23 00:00
21-year member
UID 39004
Gender Male
Status Offline
Originally posted by pengfei at 2006-10-21 05:11 AM:
You can see this paragraph is easier to understand.


@echo off
set /p ii=Please enter the string:
setlocal enabledelayedexpansion
set form=0
set ii=%ii%@
:go
if not "%ii:~0,1%"=="@" (
...


Looking at this, I feel that !=%,., but why use! instead of %?
Floor 7 Posted 2006-10-21 22:44 ·  中国 甘肃 张掖 临泽县 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
`setlocal /?` for a clearer view
Floor 8 Posted 2006-10-21 23:09 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Originally posted by yardian at 2006-10-21 11:09:



Looking at this, it doesn't equal !=%,. But why use ! instead of %?



This ! and % can't be fully explained in a few sentences.

The difference between ! and % and when to use them can't be intuitively determined,
Not entirely because their help isn't clearly written,
The main problem is:

    If there are complex assignments of various variables in SET, and values need to be passed during assignment.
    And if you encounter assigning values to variables in a for loop, and the values to be assigned are variables...
    A large number of variables are used inside and outside the FOR, assigning values to each other, passing values...
    There are also a large number of letter or variable separation operations, operating inside or outside the for...
    There are also differences between SET /A and SET A=B similar assignments, etc...
    
And so on. If you usually only write a few batch processing or use them very little,
Then the problem of! and % may not be encountered often, or if encountered, you don't know how to solve the problem of! and %,
The main reason is:

    The above series of contents are interconnected. If you learn DOS too fast, you may have lost or not thoroughly studied before starting to compile more advanced contents.

    Jumping learning and too fast learning speed, and sometimes we often ignore the most basic contents such as SET FOR in order to save time,
    Resulting in the more you learn and apply later, the more proficient the basic knowledge points required are :)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 9 Posted 2006-10-21 23:17 ·  中国 重庆 重庆石桥铺地区 电信
新手上路
Credits 8
Posts 6
Joined 2006-10-21 03:11
19-year member
UID 67416
Status Offline
Give it a support!
Floor 10 Posted 2006-10-22 19:16 ·  中国 河北 沧州 任丘市 华北油田网络
中级用户
★★
MS-DOS爱好者
Credits 397
Posts 87
Joined 2002-12-15 00:00
23-year member
UID 517
Gender Male
Status Offline
Support
Floor 11 Posted 2006-10-24 23:25 ·  中国 湖北 孝感 电信
初级用户
Credits 20
Posts 6
Joined 2006-10-01 16:01
19-year member
UID 64251
Gender Male
Status Offline
Take a close look...
Forum Jump: