中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-04 06:47
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Question about how to use set!
Printable Version  755 / 2
Floor1 caucfeiyu Posted 2007-04-19 19:02
初级用户 Posts 35 Credits 108 From 河北廊坊
Example:
@echo off&setlocal enabledelayedexpansion
set n=abc987
set "m="
set /p=!n:~-6!<nul
set /p=!m:~0,3!<nul
pause

Here  is the backspace character. I'd like to ask, doesn't set /p=!m:~0,3!<nul mean displaying 3 backspace characters, that is, deleting three characters? In this example, shouldn't the final result be abc? But when I run it, the final result is abc98. I just can't figure it out no matter how much I think about it. Why is that?
Floor2 bjsh Posted 2007-04-19 21:33
银牌会员 Posts 621 Credits 2,000
Because after this line is output there are still two spaces at the end
set /p=!n:~-6!<nul
Change the above line to
set /p"=!n:~6!!"<nul

I strongly recommend that when you use set in the future, add double quotes whenever possible;
otherwise later on you'll often run into problems with extra spaces or things getting cut off because of spaces;
and you'll often have to waste quite a lot of time looking for this error;
it's best to develop the good habit of adding quotes
Floor3 caucfeiyu Posted 2007-04-19 22:50
初级用户 Posts 35 Credits 108 From 河北廊坊
Solved, thanks, expert! Added points!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023