Page 1 of 1
Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 03:18
by Ed Dyreen
☺
Linefeed not working in DisableDelayedExpansion ?
Code: Select all
echo.begin
set $LF=^
:: Two empty lines are neccessary
echo.setlocal DisableDelayedExpansion
setlocal DisableDelayedExpansion
set var1=this!$LF!works
set "var2=this!$LF!works too"
set var3=this%$LF%fails
set "var4=this%$LF%fails too"
set var5=this^%$LF%%$LF%works
set "var6=this^%$LF%%$LF%fails"
set ^"var7=this^%$LF%%$LF%works again"
echo.%var1%
echo.%var2%
echo.%var3%
echo.%var4%
echo.%var5%
echo.%var6%
echo.%var7%
echo.setlocal EnableDelayedExpansion
setlocal EnableDelayedExpansion
echo.%var1%
echo.%var2%
echo.%var3%
echo.%var4%
echo.%var5%
echo.%var6%
echo.%var7%
pause
exit
output:
Code: Select all
begin
setlocal DisableDelayedExpansion
this!$LF!works
this!$LF!works too
this
this
this
thisecho.this
setlocal EnableDelayedExpansion
this
works
this
works too
this
this
this
thisecho.this
Druk op een toets om door te gaan. . .
Am I doing something wrong ?
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 05:44
by jeb
Hmmm, it works as I expected
try this at the end
Code: Select all
setlocal EnableDelayedExpansion
echo(!var1!
echo(!var2!
echo(!var3!
echo(!var4!
echo(!var5!
echo(!var6!
echo(!var7!
jeb
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 05:47
by Ed Dyreen
☺
in DisableDelayedExpansion ?
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:03
by jeb
If you are in DisableDelayedExpansion, you need to use percent expansion, therefore the content is parsed in the special character phase, so you need to create your variable-content in a special way, so it works after two expansions.
Code: Select all
setlocal DisableDelayedExpansion
set lf=^
set var1=Line1^^^%LF%%LF%^%LF%%LF%Line2
set var1
echo ----
echo %var1%
The content of var1 is "Line1^<LF><LF>Line2" so this can be expanded with percent, so the ^<LF><LF> will be reduced to a single <LF>
jeb
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:27
by Ed Dyreen
☺
Code: Select all
for %%! in ( @DelayedExpansion.Get.State ) do set "%%~!=echo. &set /p "?= Delayed Expansion is " <nul &if /i ["!"] neq [""] ( set /a DelayedExpansion.State = 0 &set /p "?=off" <nul ) else set /a DelayedExpansion.State = 1 &set /p "?=on" <nul"
::
%@DelayedExpansion.Get.State%
::
if /i ["%DelayedExpansion.Get.State%"] equ ["1"] setlocal DisableDelayedExpansion
::
%@DelayedExpansion.Get.State%
set $LF=^
:: Two empty lines are neccessary
set var1=Line1^^^%$LF%%$LF%^%$LF%%$LF%Line2
echo ----
echo %var1%
set \n=^^^%$LF%%$LF%^%$LF%%$LF%
set var1=Line1%\n%Line2
echo ----
echo %var1%
pause
exit
Still not working
Code: Select all
Delayed Expansion is on
Delayed Expansion is on----
Line1
Line2
----
Line1
Druk op een toets om door te gaan. . .
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:41
by jeb
Your code expands the content three times, therefore you need the obvious string of
Code: Select all
set \n=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
jeb
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:46
by Ed Dyreen
^^^%$LF%%$LF%^%$LF%%$LF%
^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
^^^^^^^^^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
I just imitate your thinking jeb because this is all quite new to me
Is this logical ?
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:57
by jeb
Nearly ...
But your last line is not correct
This should be (obviously
)
This works for four expansion cycles
Code: Select all
set $lf=^
set n4=^^^^^^^^^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
set var1=Line1%n4%Line2
set var2=%var1%
echo %var2%
jeb
Re: Linefeed not working in DisableDelayedExpansion ?
Posted: 09 Jun 2011 06:59
by Ed Dyreen
☺
Yahoo, it works ! Look at me I'm a dinosaur
Code: Select all
set ^"\n=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%"
This should be (obviously
)
Have to crunch it down, cause I'm not much of a mathematic
Code: Select all
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^^^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%