JSI Tip 9915. Another way to change the case of a string to all upper case or all lower case?

Jerold Schulman

November 20, 2005

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


In tip 8971, I scripted ChgCase.bat to change a string to all upper case or all lower case.

I have re-written 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, NOT %VarName%, that contains the string to be converted.

Example:

set VarName=abc123xyz
call ChgCase U VarName

will convert the string in VarName to ABC123XYZ.

ChgCase.bat contains:

@echo offif {%2}=={} goto :errif exist "%TEMP%ChgCase.vbs" goto [email protected] objArguments, ul, iString>"%TEMP%ChgCase.vbs"@echo.Set objArguments = Wscript.Arguments>>"%TEMP%ChgCase.vbs"@echo.ul=objArguments(0)>>"%TEMP%ChgCase.vbs"@echo.iString=objArguments(1)>>"%TEMP%ChgCase.vbs"@echo.if UCase(ul) = "U" Then>>"%TEMP%ChgCase.vbs"@echo. WScript.Echo UCase(iString)>>"%TEMP%ChgCase.vbs"@echo.ELSE>>"%TEMP%ChgCase.vbs"@echo. WScript.Echo LCase(iString)>>"%TEMP%ChgCase.vbs"@echo.End If>>"%TEMP%ChgCase.vbs"goto doit:err@echo Syntax: ChgCase U^|L VarNamegoto :EOF:doitif /i {%1} EQU {U} goto OKulif /i {%1} NEQ {L} goto err:OKulfor /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%ChgCase.vbs" %1 %%%2%%') do ( set %2=%%a)



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