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-06-20 06:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Understanding the interception function of variable characters in CMD View 22,969 Replies 100
Original Poster Posted 2006-12-17 06:35 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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 ]
Recent Ratings for This Post ( 20 in total) Click for details
RaterScoreTime
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-03-17 11:46
qinbuer +2 2007-06-01 02:03
26933062 +4 2007-06-04 23:50
zouzhxi +4 2007-06-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-01-04 21:21
313885174 +2 2008-01-26 12:34
hy433124shc +2 2008-02-20 19:14
easonL +2 2008-05-27 13:44
dywjzh -1 2008-09-09 11:43
shifengl +1 2009-05-21 08:38
a7147125 +1 2009-08-23 23:35
mwm5 +1 2009-10-17 20:49
gool123456 +1 2010-05-04 20:02
Floor 2 Posted 2006-12-17 06:46 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Thanks to brother lxmxn, it has been of great help to beginners like us!
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 3 Posted 2006-12-17 06:51 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
cheng342709 +1 2008-04-27 14:24
Floor 4 Posted 2006-12-17 07:41 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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.
Floor 5 Posted 2006-12-17 07:47 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
So wonderful~~
Why did the font become smaller?
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 6 Posted 2006-12-17 07:57 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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.
Floor 7 Posted 2006-12-17 08:01 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Good stuff, learning.
Floor 8 Posted 2006-12-17 10:03 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Learned. Good post.
Windows 一键还原
http://www.yjhy.com
Floor 9 Posted 2006-12-17 21:49 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 10 Posted 2006-12-17 22:03 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
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.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 11 Posted 2006-12-18 00:07 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
Floor 12 Posted 2006-12-18 03:21 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  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.
Floor 13 Posted 2006-12-18 03:35 ·  中国 广东 广州 天河区 电信
初级用户
Credits 56
Posts 25
Joined 2006-11-26 09:48
19-year member
UID 71778
Gender Male
Status Offline
Classic, newcomers are in for a treat! Hehe
Floor 14 Posted 2006-12-24 23:59 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Wonderful~~Bump up this great post~:)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 15 Posted 2007-01-13 21:41 ·  中国 广东 湛江 电信
初级用户
Credits 22
Posts 10
Joined 2007-01-12 09:58
19-year member
UID 76274
Gender Male
Status Offline
Good stuff, so good that it's hard to describe. It turns out that batch processing has such detailed functions.
1 2 3 7 Next ›
Forum Jump: