set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
SET memoli=%token:QMZ=%NL%%%
echo %memoli%>>%tmp%\list2.txt
I cant change the string "QMZ" with a new line. How to do that?
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
SET memoli=%token:QMZ=%NL%%%
echo %memoli%>>%tmp%\list2.txt
I cant change the string "QMZ" with a new line. How to do that?
Very simple
setlocal EnableDelayedExpansion
set "token=HelloQMZworld"
echo !token:QMZ=^
!
It works as the batch parser parses first the multiline caret and replace it with a single linefeed.
Then in the delayed expansion phase it replaces the QMZ with a single linefeed, which is legal in that phase.
To set a new variable with the replaced string simply use
setlocal EnableDelayedExpansion
set "token=HelloQMZworld"
set newVal=!token:QMZ=^
!
echo !newVal!
set LF=^
rem ** Two empty lines required
FOR /F "delims=" %%a in ("%token:QMZ=!LF!%") do (
echo %%a>>%tmp%\list2.txt
)
I was just wandering in the codes and I just did this unconsciously. But it does the trick.