中国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-02 20:19
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Question about uppercase/lowercase conversion???
Printable Version  1,427 / 6
Floor1 sunyao Posted 2006-12-19 05:14
初级用户 Posts 60 Credits 141 From 天津
The system is 2k
set /p con="Continue (Y/N):"

set con=%con:y=Y%
set con=%con:n=N%

if %con%==Y goto continue
if %con%==N goto out
Written in a cmd script, while the program is running, echo %con%
I found that con at this point is y=Y
That is to say, con is now equal to the expression y=Y
Then when if does the check it becomes if y=Y==Y goto continue
But this line gives a syntax error in 2003, and I don't know why
Also, after executing set con=%con:y=Y% at the command line
echo %con% at this point con is equal to Y
Why does the command behave differently at the command line and in a script?
Floor2 redtek Posted 2006-12-19 12:17
金牌会员 Posts 1,147 Credits 2,902



The if /i parameter can judge without distinguishing uppercase or lowercase~:)
Floor3 sunyao Posted 2006-12-19 22:22
初级用户 Posts 60 Credits 141 From 天津
Then this line set con=%con:y=Y%
when written in a cmd script
why does con become y=Y? I don't understand
Floor4 sunyao Posted 2006-12-19 22:43
初级用户 Posts 60 Credits 141 From 天津
Also in 2003
if /i %con%==Y goto continue
it still gives an error
Floor5 redtek Posted 2006-12-19 23:24
金牌会员 Posts 1,147 Credits 2,902
To prevent conflicts caused by empty variables or unexpected symbols, you must



You must wrap the variable being compared with some kind of symbol, like the " " square brackets above, so that if can read it clearly and cleanly. With well-structured code, the chance of errors is smaller~:)

The if /i parameter already ignores case, so there is no need to write the line set con=%con:y=Y% anymore~:)


If you don't like using the equals sign for comparison, then if also provides the following forms:



[ Last edited by redtek on 2006-12-19 at 10:25 AM ]
Floor6 sunyao Posted 2006-12-19 23:30
初级用户 Posts 60 Credits 141 From 天津
Got it, thanks redtek
Floor7 mackyliu Posted 2006-12-20 00:50
初级用户 Posts 16 Credits 32
Not bad, learned something.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023