|
yardian
中级用户
  
积分 305
发帖 85
注册 2005-5-23
状态 离线
|
『楼 主』:
授人鱼不如授人渔,请教关于!的用法
使用 LLM 解释/回答一下
这是坛子 里的一位老大给我的代码,可是不会渔,所以一直不会改为已用.哪位大侠能解释一下,最好能详细解释一下形如:!num!,!ii:~0,1!.
!是怎么用的?这个%ii:~0,1%,可以从set /?里找到.但!ii:~0,1!这里换成!意思一样吗?
Last edited by yardian on 2006-10-21 at 00:16 ]
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 ]
|
|
2006-10-20 22:38 |
|
|
yardian
中级用户
  
积分 305
发帖 85
注册 2005-5-23
状态 离线
|
|
2006-10-21 04:54 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
你看这一段更容易懂.
@echo off
set /p ii=请输入字符串:
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
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
|
|
2006-10-21 05:11 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
还有一个笨的方法:)
用你适先定义好的要被查找的字符串,
用它们替换掉用户输入的内容中相同的字符串,
把它们替换为一个用户不太容易或不太可能出现的一个标置字符,
用这个字符(被替换成了首位)来比较我们适先定义的一个符号(如“氵”),
如果有这个符号,说明成功替换了,说明用户输入的内容含有YES,
如果没有这个符号,说明没有成功替换,所以就是不包含。
……
@echo %dbg% off && setlocal enabledelayedexpansion
set /p ii=请输入字符串:
set ii=%ii:*yes=氵% && set ii=%ii:~0,1%
if /i "!ii!"=="氵" (echo 发现yes字符!) else (echo 没有发现yes字符.)
Last edited by redtek on 2006-10-21 at 08:00 ]
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,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-21 07:46 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by yardian at 2006-10-20 22:38:
:!num!,!ii:~0,1!.
!是怎么用的?这个%ii:~0,1%,可以从set /?里找到.但!ii:~0,1!这里换成!意思一样吗?
%ii:~0,1% (含义:取%ii%变量的第一个字符,从偏移量0开始)
(它的具体含义要查询 for /? ,这个FOR的帮助很全)
(这个有很多种用法,非常多,一堆话也说不完,需要照着帮助来一个一个运行一下来理解)
其它的内容请查询以下等帮助信息:
SET /?
FOR /?
SETLOCAL /?
IF /?
其中 FOR 中有针对!这个符号的使用的详细说明,但还需要反复理解和运行试验:)
否则无法理解透:)
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,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-21 07:58 |
|
|
yardian
中级用户
  
积分 305
发帖 85
注册 2005-5-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-10-21 05:11 AM:
你看这一段更容易懂.
@echo off
set /p ii=请输入字符串:
setlocal enabledelayedexpansion
set form=0
set ii=%ii%@
:go
if not "%ii:~0,1%"=="@" (
...
看这个感觉!=%,.但为什么要用!而不用%呢?
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 %?
|
|
2006-10-21 11:09 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
setlocal /? 看的更清楚
`setlocal /?` for a clearer view
|
|
2006-10-21 22:44 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by yardian at 2006-10-21 11:09:
看这个感觉!=%,.但为什么要用!而不用%呢?
这个!和%如果用几句话来概括,还是不能把它们的精华说尽。
!与%无法直观的认定它们的区别和应该在什么时候使用,
不全是因为它们的帮助没有写清楚,
最主要的问题是:
如果 SET 的各种变量复杂赋值,在赋值中还要传递值。
而且如果遇到了要在 for 的循环中给变量赋值,所赋的值又是变量……
大量的变量在 FOR 中和在 For 外部应用,相互赋值、传值……
还有大量的字母或变量分隔操作,在for中或在for外面操作等等
还有关于 SET /A 和 SET A=B 的类似赋值的区别等等……
等等一系列操作,如果平时使用时只编过几个批处理或者应用的非常少,
那么!与%的问题很可能不常遇到,或者遇到了!与%的问题不知道如何而解,
最主要的原因在于:
上面的一系列内容的知识点都是相连着的,如果学习DOS过快,很可能丢掉了或没有学透就开始编更高级的内容所致。
跳跃性学习和学习速度过快,而为了争取时间有时候我们常会忽略最基本的内容,如SET FOR等等,
就导致了越向后学习与应用,所需要的基本知识点要求越要精通:)
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,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-21 23:09 |
|
|
yeesong2002
新手上路

积分 8
发帖 6
注册 2006-10-21
状态 离线
|
|
2006-10-21 23:17 |
|
|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
|
2006-10-22 19:16 |
|
|
zoub
初级用户
 
积分 20
发帖 6
注册 2006-10-1
状态 离线
|
|
2006-10-24 23:25 |
|
|