How-to: Upper or Lower case a String

The examples on this page utilise some advanced techniques to make a string UPPER or lower case:

This function can be used to return a string converted to be lower case.

@Echo off
:toLower str -- Converts uppercase characters to lowercase
::              Converts the supplied environment variable (%1) to lowercase.
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%%
)
Echo Results saved to variable [%%%1%%]
Call echo %%%1%%
EXIT /b
:$source dostips.com

Examples

@Echo off
Setlocal
Set "_myvar=This is A DEMO STrIng!"
Call ToLower.cmd _myvar
Echo [%_myvar%]

C:\> this is a demo string!

Upper case a String - ToUpper.cmd

This function can be used to return a string converted to be upper case.

@Echo off
:toUpper str -- converts lowercase character to uppercase
::           -- str [in,out] - valref of string variable to be converted
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%%
    
)
Echo Results saved to variable [%%%1%%]
Call echo %%%1%%
EXIT /b

:$source dostips.com

Example

@Echo off
Setlocal
Set "_var=some example @$']£ TEXT 123!" Call ToUpper.cmd _var SOME EXAMPLE @$']£ TEXT 123!

“Phrasing is the idea of finding sentences and using punctuation in speech. I often look at the score to see what’s written in by the composer to see if I can find clues to those directions, like what direction did the composer have in mind, and I try to incorporate those things as much as possible” ~ Hilary Hahn

Related commands

How-to: VarSubstring - Extract part of a variable (substring)
How-to: VarSearch - Search & replace part of a variable.
How-to: StrLen - Calculate the length of a string.
String Manipulation - Split, indexof, lastindexof, reverse, endsWith, startsWith - SS64 forum
PowerShell: $var.ToLower() or $var.ToUpper()
Tail/Head - SS64 forum
ToUpper /Lower - DosTips function library.


 
Copyright © 1999-2024 SS64.com
Some rights reserved