0
set "a=6=5"
echo %a%
6=5

echo "%a:6=5=6-5%"
"5=6-5=5"

should give me (the expected answer) 6-5 instead.

I've escaped = after expression to be replaced, but the = in the expression is treated by CMD as the delimiter of the substituent.

echo "%a:6=5^=6-5%"
"5^=6-5=5"

echo %a:"6=5"="6-5"%
6=5

echo %a:"6^=5"="6-5"%
6=5

How should I structure it to get 6-5 to replace 6=5?

Zimba
  • 2,854
  • 18
  • 26

1 Answers1

0

Solution via for loop in last line. No delimit characters work for =:

for /f "delims==" %i in ('echo %a%') do echo %i
6 5
for /f "delims==" %i in ('echo %a%') do echo %i,
6 5,
for /f "delims=^=" %i in ('echo %a%') do echo %i,
6 5,
for /f "delims=\=" %i in ('echo %a%') do echo %i,
6 5,
for /f "delims===" %i in ('echo %a%') do echo %i,
6 5,
for /f "delims=`=" %i in ('echo %a%') do echo %i,
6 5,
for /f "delims=`=" %i in ('echo %a%') do set i=%i& echo !i: =-!
6-5
Zimba
  • 2,854
  • 18
  • 26