Page 1 of 1

tolower

Posted: 04 May 2010 12:09
by Waldo120
Hi, I'm trying to use the tolower function described in the below page. I think this is a simple syntax problem since I'm relatively new to DOS functions.

http://www.dostips.com/DtTipsStringOper ... on.toLower

I'm trying to take %username% and make it all lower case (or even upper case). Since when I test for "if %username%==administrator" it depends on weather I choose to logon as Administrator or administrator or ADMINistrator.

I've tried (yes, I copied the function into my bat file):
call:tolower %username%
call:tolower %username% %username%
call:tolower %username% %usernamelower%

None of these result in my user name with all lowers.

Any help is appreciated.

Re: tolower

Posted: 04 May 2010 12:36
by aGerman
The parameter is only the name of the variable.
Example:

Code: Select all

@echo off &setlocal
echo %username%
call :toLower username
echo %username%
pause
goto :eof

: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


But you don't need it for a comparison. Use
if /i ...
to ignore upper and lower case.

Regards
aGerman

Re: tolower

Posted: 04 May 2010 23:41
by Waldo120
Awesome the /i switch worked.

Thanks.