tolower

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Waldo120
Posts: 2
Joined: 04 May 2010 11:57

tolower

#1 Post by Waldo120 » 04 May 2010 12:09

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: tolower

#2 Post by aGerman » 04 May 2010 12:36

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

Waldo120
Posts: 2
Joined: 04 May 2010 11:57

Re: tolower

#3 Post by Waldo120 » 04 May 2010 23:41

Awesome the /i switch worked.

Thanks.

Post Reply