toggle case

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Sponge Belly
Posts: 231
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

toggle case

#1 Post by Sponge Belly » 18 Dec 2021 19:44

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

AR Coding
Posts: 53
Joined: 02 May 2021 21:16

Re: toggle case

#2 Post by AR Coding » 18 Dec 2021 22:38


T3RRY
Posts: 250
Joined: 06 May 2020 10:14

Re: toggle case

#3 Post by T3RRY » 19 Dec 2021 03:03

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.

Post Reply