can you set multiple lines into one variable?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BatMaster
Posts: 28
Joined: 22 Dec 2010 12:53

can you set multiple lines into one variable?

#1 Post by BatMaster » 02 Oct 2011 12:21

hey guys
i was just wondering if its possible to set multiple lines into one variable
if it is please tell me if not tell me anyway

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: can you set multiple lines into one variable?

#2 Post by aGerman » 02 Oct 2011 16:08

It's possible and you will find a few examples in this forum.

Code: Select all

@echo off
:: Create LineFeed character ::::::::::::::
set lf=^


:: Two empty lines above are neccessary! ::

set "line1=Hello"
set "line2=World!"

setlocal enabledelayedexpansion
:: merge both variables
set "var=!line1!!lf!!line2!"
:: display the result
echo !var!
endlocal

pause

Regards
aGerman

BatMaster
Posts: 28
Joined: 22 Dec 2010 12:53

Re: can you set multiple lines into one variable?

#3 Post by BatMaster » 03 Oct 2011 10:37

Thanks alot that realy helps
-=BatMaster=-
:D :D :D :D :mrgreen:

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: can you set multiple lines into one variable?

#4 Post by Rileyh » 08 Oct 2011 01:27

aGerman,
What are the "!!" for?

Rileyh

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: can you set multiple lines into one variable?

#5 Post by aGerman » 08 Oct 2011 08:57

The ! replaces the % for environment variables if enabledelaiedexpansion was set and you have to expand this variable more than once in a command line or a block.

Regards
aGerman

Post Reply