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


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 off
if \{%2\}==\{\} goto :err
if exist "%TEMP%\ChgCase.vbs" goto doit
@echo.Dim 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 VarName
goto :EOF
:doit
if /i \{%1\} EQU \{U\} goto OKul
if /i \{%1\} NEQ \{L\} goto err
:OKul
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\ChgCase.vbs" %1 %%%2%%') do (
 set %2=%%a
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish