JSI Tip 8971. How can I change the case of string to all upper case or all lower case?

Jerold Schulman

January 24, 2005

2 Min Read
ITPro Today logo in a gray background | ITPro Today


In tip 6301, I determined if a string is all alphabetic or all numeric. In tip 6302, I determined if an all alphabetic string is all upper case or all lower case.

NOTE: See Another way to change the case of string to all upper case or all lower case?

I have scripted ChgCase.bat to change a string to all upper case or all lower case.

The syntax for using ChgCase.bat is:

call ChgCase U|L VarName

Where:

U        changes the string in VarName to upper case.L        changes the string in VarName to lower case.VarName  is the name of the variable that contains the string to be converted.

Sample Usage:

Update all users displayName attributes so that the first character in each name segment is upper case and the remaining characters are lower case:

@echo offsetlocalset filter="(&(objectCategory=Person)(objectClass=User))"set qry=DSQUERY * domainroot -filter %filter% -attr distinguishedName displayName -L -limit 0for /f "Tokens=1*" %%a in ('%qry%') do ( set attr=%%a set data=%%b call :doit1)endlocalgoto :EOF:doit1if "%attr%" EQU "distinguishedName:" set userDN=%data%&goto :EOFif "%data%" EQU "" goto :EOFcall echo %data%|FIND "=">nulif %ERRORLEVEL% EQU 0 goto :EOFcall :doit2 %data%if "%data%" EQU "%name:~1%" goto :EOFDSMOD user "%userDN%" -Display "%name:~1%"goto :EOF:doit2set name=:doit3if {%1}

{} goto :EOFset s=%1set v1=%s:~0,1%set vx=%s:~1%call ChgCase U v1call ChgCase L vxset name=%name% %v1%%vx%shiftgoto doit3

ChgCase.bat contains:

@echo offIf {%2}{} goto :err:: Test for nul value and exitfor /f "Tokens=*" %%c in ('@echo %%%2%%') do if {%%c}
{%%%2%%} goto :EOFIf /i {%1}
{U} goto UCaseIf /i {%1}=={L} goto LCase:err@echo Syntax: ChgCase U^|L VarNamegoto :EOF:UCasefor %%c 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 call set %2=%%%2:%%c=%%c%%goto :EOF:LCasefor %%c 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 call set %2=%%%2:%%c=%%c%%

uppercase lowercase



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like