|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
   『楼 主』:
[CMD]理解变量字符的截取功能
使用 LLM 解释/回答一下
其实CMD里面变量的字符截取功能很实用,但是有的朋友还没有真正理解里面的规律,所以今天特意写了以下代码,希望对新手朋友理解CMD下面变量的字符截取功能有所帮助。
::code by lxmxn @ cn-dos.net .
::目的:帮助新手们更好的理解变量字符截取功能.
::Date 2006-12-16 .
::说明:有的变量截取之后值为空,这是正常的.
@echo off&setlocal EnableDelayedexpansion
::设置变量var的值:
set var=0123456789ABCDEF
call :begin
for /l %%a in (1,3,15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (1,4,15) do (
for /l %%b in (-1,-3,-15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-2,-3,-15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-1,-4,-15) do (
for /l %%b in (-2,-3,-15) do (
call :printf %%a %%b
)
)
pause
endlocal&cls&echo.
echo 演示结束了,任意键退出……
pause>nul
goto :eof
::输出结果:
:printf
echo %%var:~%1,%2%% 截取之后的字符为: !var:~%1,%2!
goto :eof
::清理屏幕:
:begin
echo\&pause&cls&echo.
echo 变量var的值为: %var%
echo.
goto :eof
点击这里下载附件(Getstr.rar)
Last edited by lxmxn on 2007-10-31 at 06:33 PM ]
In fact, the character interception function of variables in CMD is very practical, but some friends haven't really understood the rules inside. So today I specially wrote the following code, hoping to help novice friends understand the character interception function of variables under CMD.
::code by lxmxn @ cn-dos.net .
::Purpose: To help novices better understand the variable character interception function.
::Date 2006-12-16 .
::Description: Some variables may have empty values after interception, which is normal.
@echo off&setlocal EnableDelayedexpansion
::Set the value of variable var:
set var=0123456789ABCDEF
call :begin
for /l %%a in (1,3,15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (1,4,15) do (
for /l %%b in (-1,-3,-15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-2,-3,-15) do (
for /l %%b in (1,4,15) do (
call :printf %%a %%b
)
)
call :begin
for /l %%a in (-1,-4,-15) do (
for /l %%b in (-2,-3,-15) do (
call :printf %%a %%b
)
)
pause
endlocal&cls&echo.
echo The demonstration is over, press any key to exit...
pause>nul
goto :eof
::Output result:
:printf
echo %%var:~%1,%2%% The intercepted character is: !var:~%1,%2!
goto :eof
::Clear the screen:
:begin
echo\&pause&cls&echo.
echo The value of variable var is: %var%
echo.
goto :eof
Click here to download the attachment (Getstr.rar)
Last edited by lxmxn on 2007-10-31 at 06:33 PM ]
此帖被 +51 点积分 点击查看详情 评分人:【 ccwan 】 | 分数: +5 | 时间:2006-12-17 06:45 | 评分人:【 zh159 】 | 分数: +5 | 时间:2006-12-17 06:52 | 评分人:【 redtek 】 | 分数: +5 | 时间:2006-12-17 21:20 | 评分人:【 lianjiang2004 】 | 分数: +4 | 时间:2006-12-17 21:30 | 评分人:【 HUNRYBECKY 】 | 分数: +5 | 时间:2007-3-17 11:46 | 评分人:【 qinbuer 】 | 分数: +2 | 时间:2007-6-1 02:03 | 评分人:【 26933062 】 | 分数: +4 | 时间:2007-6-4 23:50 | 评分人:【 zouzhxi 】 | 分数: +4 | 时间:2007-6-28 15:58 | 评分人:【 fengjian 】 | 分数: +1 | 时间:2007-10-31 18:01 | 评分人:【 upsco 】 | 分数: +1 | 时间:2007-11-21 21:18 | 评分人:【 xiaohacker 】 | 分数: +2 | 时间:2007-12-23 20:32 | 评分人:【 haiou327 】 | 分数: +4 | 时间:2008-1-4 21:21 | 评分人:【 313885174 】 | 分数: +2 | 时间:2008-1-26 12:34 | 评分人:【 hy433124shc 】 | 分数: +2 | 时间:2008-2-20 19:14 | 评分人:【 easonL 】 | 分数: +2 | 时间:2008-5-27 13:44 | 评分人:【 dywjzh 】 | 分数: -1 | 时间:2008-9-9 11:43 | 评分人:【 shifengl 】 | 分数: +1 | 时间:2009-5-21 08:38 | 评分人:【 a7147125 】 | 分数: +1 | 时间:2009-8-23 23:35 | 评分人:【 mwm5 】 | 分数: +1 | 时间:2009-10-17 20:49 | 评分人:【 gool123456 】 | 分数: +1 | 时间:2010-5-4 20:02 |
|
|
|
2006-12-17 06:35 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
谢谢lxmxn兄,对我等新手帮助很大啊!
Thanks to brother lxmxn, it has been of great help to beginners like us!
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-17 06:46 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
建议大家复制代码保存为BAT文件后在“截取之后的字符为”“变量var的值为”之前用TAB加一个制表符,这样显示就整洁了
It is suggested that everyone copy the code, save it as a BAT file, and then add a tab character with TAB before "The character after interception is" and "The value of variable var is", so that the display will be neat.
|
|
2006-12-17 06:51 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Re ccwan :
汗,你还是新手啊?
多谢加分鼓励。^_^
Re zh159 :
多谢兄的提议和加分。
自己把帖子重新编辑了半天,但是可惜的是最终还是没有达到整齐的显示效果。最后只能以附件的形式让大家下载了。
Re ccwan :
Sweat, are you still a newbie?
Thanks for the plus points and encouragement. ^_^
Re zh159 :
Thanks for your proposal and plus points, brother.
I spent a long time re-editing the post, but unfortunately, I still didn't achieve a neat display effect in the end. Finally, I had to let everyone download it as an attachment.
|
|
2006-12-17 07:41 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
太精彩了~~
字体为什么变小了?
So wonderful~~
Why did the font become smaller?
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-17 07:47 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by redtek at 2006-12-17 07:47:
太精彩了~~
字体为什么变小了?
兄所说的字体变小了,是指的什么?我主题的字体变大了才对呀。
Originally posted by redtek at 2006-12-17 07:47:
So wonderful~~
Why did the font become smaller?
What you mentioned about the font becoming smaller, what exactly are you referring to? My theme's font has become larger instead.
|
|
2006-12-17 07:57 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
|
2006-12-17 08:01 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
|
2006-12-17 10:03 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-12-17 21:49 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
若是因字小不好读,可以按住Ctrl键,然后向上转动鼠标滑轮就大了,向下是变小。
If the characters are too small and hard to read, you can hold down the Ctrl key and then scroll the mouse wheel upward to make them larger, and scroll downward to make them smaller.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-17 22:03 |
|
|
wydos
中级用户
  
积分 304
发帖 117
注册 2006-4-4
状态 离线
|
|
2006-12-18 00:07 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
把字体调整了一下,大家再看字体有多大。
我昨天特意把字体调整得比较大,今天上论坛怎么突然一下变很小了,不知道是什么原因。
Adjusted the font, let's see how big the font is now.
I specifically adjusted the font to be relatively large yesterday, but today when I came to the forum, it suddenly became very small. I don't know the reason.
|
|
2006-12-18 03:21 |
|
|
freeapple
初级用户
 
积分 56
发帖 25
注册 2006-11-26
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
经典,新手有福了!呵呵
Classic, newcomers are in for a treat! Hehe
|
|
2006-12-18 03:35 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
精彩~~好贴子顶起来~:)
Wonderful~~Bump up this great post~:)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-24 23:59 |
|
|
xuzhenhui
初级用户
 
积分 22
发帖 10
注册 2007-1-12
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
好东西,好得说不出,原来批处理还有如此细致的功能.
Good stuff, so good that it's hard to describe. It turns out that batch processing has such detailed functions.
|
|
2007-1-13 21:41 |
|