.bat file to create a complex string variable with special characters

NewQueries picture NewQueries · Feb 16, 2012 · Viewed 20k times · Source

I need to create a single string variable by concatenating multiple strings. The final string i need is as below

<Workspace name="RealTimeRiskUSD_UA" path="C:\workspace" IsAdmin="false" />

This is what i tried.

echo off
set path1="<Workspace "
set name="name="RealTimeRiskUSD_UA"" 
set path2="path="C:\workspace" IsAdmin="false" />"
set fullpath=%path1%%name%%path2%
echo %path1%
echo %name%
echo %path2%
echo %fullpath%

I also tried using the below link to remove the double quotes from each string but does not work
http://ss64.com/nt/syntax-esc.html

Answer

jeb picture jeb · Feb 16, 2012

You could use the extended syntax of SET. set "var=content".

This escapes special characters, but the quotes aren't part of the string.

echo off
Setlocal EnableDelayedExpansion
set "path1=<Workspace " 
set "name=name="RealTimeRiskUSD_UA"" 
set "path2=path="C:\workspace" IsAdmin="false" />" 
set "fullpath=%path1%%name%%path2%"
echo !fullpath!