I found a code which converts lower cases to upper cases, but have no idea how to interpret the code:
SET %~1=!%1:b=B!
I know it changes in variable %1 character b to B, but I don't uderstand how it is related to the SET command.
I found explanation for "SET %PATH:str1=str2%" - but this is not the same.
Where I can find explanation for SET %~1=!%1:b=B!
Thanks,
Zalek
What does it means: SET %~1=!%1:b=B!
Moderator: DosItHelp
Re: What does it means: SET %~1=!%1:b=B!
'
I'll decompile a similar command into it's elements
We are taking advantage of the fact that set is case insensitive.
But this particular code depends on delayed expansion, try this:
%~1 is the first parameter that was passed, %~2 the 2nd etc... %~0 is your batch in question, %* is entire input.
I'll decompile a similar command into it's elements
Code: Select all
for %%! in ( !ALPHABET.LCASE! ) do set "$=!$:%%!=%%!!"
::
for %%! in ( a b c d e f g h i j k l m n o p q r s t u v w x y z ) do set "$=!$:%%!=%%!!"
::
for %%! in ( a ) do set "$=!$:%%!=%%!!"
::
set "$=!$:A=a!"
But this particular code depends on delayed expansion, try this:
Code: Select all
@echo off
set "$Var=HELLO"
set "$Var=%$Var:l=l%"
set "$Var=%$Var:e=e%"
set "$Var"
pause
exit /b
-
- Posts: 126
- Joined: 10 Jun 2011 10:30
Re: What does it means: SET %~1=!%1:b=B!
@Ed,
I think part of the problem is that his Example is wrong. It's not SET %PATH:str1=str2%...
It should be SET PATH=%PATH:str1=Str2% and then it not only works, but it also mimics his example question:
Now the only difference is the ! being used for delayed expansion and the ~ being used to remove quotes.
The explanation of ~ can be found in both SET /? at the end and CALL /?
The explanation of ! used for delayed expansion can be found in SET /? and FOR /?
If you want, you can paste the full code you're referring to and I will attempt to explain it and Ed will correct me when I am wrong
I think part of the problem is that his Example is wrong. It's not SET %PATH:str1=str2%...
It should be SET PATH=%PATH:str1=Str2% and then it not only works, but it also mimics his example question:
Code: Select all
SET PATH=%PATH:str1=Str2%
SET %~1=!%1:str1=str2!
Now the only difference is the ! being used for delayed expansion and the ~ being used to remove quotes.
The explanation of ~ can be found in both SET /? at the end and CALL /?
The explanation of ! used for delayed expansion can be found in SET /? and FOR /?
If you want, you can paste the full code you're referring to and I will attempt to explain it and Ed will correct me when I am wrong
Re: What does it means: SET %~1=!%1:b=B!
'
You got me Acy I completely missed that
You got me Acy I completely missed that