Page 1 of 1

toggle case

Posted: 18 Dec 2021 19:44
by Sponge Belly
Hello All! :)

Sorry I haven't posted in a while. To borrow Harold Macmillan’s immortal line:
Events, my dear boy, events.
Anyways, here’s a little something I’ve been working on:

Code: Select all

@echo off & setLocal enableExtensions disableDelayedExpansion
(call;) %= sets errorlevel to 0 =%
set ^"toggled=AaAaBbBbCcCcDdDdEeEeFfFfGgGgHhHhIiIiJjJjKkKkLlLlMmMm^
NnNnOoOoPpPpQqQqRrRrSsSsTtTtUuUuVvVvWwWwXxXxYyYyZzZz"
set "targetChr="

call :toggleCase w targetChr
set targetChr
goto end

:die
echo(unexpected end of program
(call) %= sets errorlevel to 1 =%
:end
endLocal & goto :EOF

:toggleCase
setLocal
for /f "delims=%1 tokens=2" %%A in ("#%toggled%") do (
        endLocal & set "%2=%%A"
) %= for /f =%
exit /b 0 %= toggleCase =%
So, if you pass lowercase w to the :toggleCase subroutine, it will return uppercase W. Similarly, if you specify uppercase X, lowercase x will be the result.

Next, I hope to extend :toggleCase to process whole strings. But I'm so busy these days, you may be waiting a while! :lol:

Happy Holidays!

- SB

Re: toggle case

Posted: 18 Dec 2021 22:38
by AR Coding

Re: toggle case

Posted: 19 Dec 2021 03:03
by T3RRY
AR Coding wrote:
18 Dec 2021 22:38
Hi,
doesnt Dostips already have such a function?
www.dostips.com/DtCodeCmdLib.php#Function.toLower
www.dostips.com/DtCodeCmdLib.php#Function.toUpper
This utility appears different in the sense only target characters will have case toggled, as opposed to converting the case of an entire string.