(Please explain how the above line works.)
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET String=%1
Set Case=%2
if !Case!==low goto :lo
goto :hi
rem SET String
:hi
echo in hi
CALL :toUpper String
SET String
goto :EOF
SET String
:lo
echo in lo
CALL :toLower String
SET String
ENDLOCAL
rem GOTO:EOF
exit /b
:toUpper
rem Description: call:toUpper str
:toUpper str -- converts lowercase character to uppercase
:: -- str [in,out] - valref of string variable to be converted
:$created 20060101 :$changed 20080219 :$categories StringManipulation
:$source http://www.dostips.com
if not defined %~1 EXIT /b
for %%a in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I"
"j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R"
"s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z" "Σ=─"
"÷=╓" "ⁿ=▄") do (
call set %~1=%%%~1:%%~a%%
)
EXIT /b
rem :toLower - converts uppercase character to lowercase
rem Description: call:toLower str
:toLower str -- converts uppercase character to lowercase
:: -- str [in,out] - valref of string variable to be converted
:$created 20060101 :$changed 20080219 :$categories StringManipulation
:$source http://www.dostips.com
if not defined %~1 EXIT /b
for %%a in ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i"
"J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r"
"S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z" "─=Σ"
"╓=÷" "▄=ⁿ") do (
call set %~1=%%%~1:%%~a%%
)
EXIT /b
Output:
C:\test>tipsUL.bat BILL.TXT low
in lo
String=bill.txt
C:\test>tipsUL.bat bill.txt hi
in hi
String=BILL.TXT
C:\test>tipsUL.bat abc hi
in hi
String=ABC
C:\test>echo ABC | awk {'print tolower($_)'}
abc
C:\test>echo abc | awk {'print toupper($_)'}
ABC