There is no native batch command that can conveniently do case sensitive string manipulation. A native batch solution would have to build a new string character by character in a loop. Very doable - but a pain and also inefficient.
EDIT - Long ago I wrote a pure batch utility called modFile.bat that does a case sensitive find/replace on the content of a text file. Performance isn't bad, but it does have some restrictions. I rarely use that code. I had written a companion routine to do case sensitive find/replace on a variable instead of a text file, but I seem to have lost that code.
Today I pretty much always use JREPL.BAT whenever I want to manipulate text.
The JREPL.BAT solution for your example should be:
for /f delims^=^ eol^= %%A in ('jrepl t X /s test') do set "test=%%A"
But there seems to be a bug. It works if the variable name is some name other than test
. Looks like I have some debugging to do.
Until the bug is fixed, you can use:
for /f delims^=^ eol^= %%A in ('cmd /v:on /c "echo(!test!)|jrepl t X"') do set "test=%%A"
Update: The bug has been fixed in version 3.4 The /S
option now works with a variable named TEST
.