.bat to create a complex string variable with special characters

I need to create one string variable by combining multiple strings. The last line I need is 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 link below to remove double quotes from each line, but it doesn't work. http://ss64.com/nt/syntax-esc.html

+6
source share
1 answer

You can use the advanced SET syntax. set "var = content".

This eludes special characters, but quotation marks are not 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! 
+9
source

Source: https://habr.com/ru/post/908661/


All Articles