The code below echo s two "B"s and not one B and an "a". Can someone explain to me why this is and how to get the result I want.
@echo off
set code=A
set code=%code:A=B%
echo %code%
set code=a
set code=%code:A=B%
echo %code%
pause
The code below echo s two "B"s and not one B and an "a". Can someone explain to me why this is and how to get the result I want.
@echo off
set code=A
set code=%code:A=B%
echo %code%
set code=a
set code=%code:A=B%
echo %code%
pause
Got this and edited it to fit your question from this question
@echo off
setlocal enabledelayedexpansion
set "string=AaBbCc"
set "result="
for /l %%G in (0,1,999) do (
set char=!string:~%%G,1!
if "!char!" equ "A" set "char=B"
set "result=!result!!char!"
)
echo %result%
endlocal
pause
It works by going through each character (max of ~1000) and replacing a literal string "A" with "B". This can be slower on longer strings but should work fine. delayedExpansion
needs to be enabled to reference the string it builds up 1 character at a time.